Fix segfaults in the formatter.
authorManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 10:09:28 +0000 (10:09 +0000)
committerManuel Klimek <klimek@google.com>
Wed, 23 Jan 2013 10:09:28 +0000 (10:09 +0000)
Also: expletive deleted.
llvm-svn: 173247

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index bdcf5b6..90bcf6f 100644 (file)
@@ -1049,7 +1049,7 @@ public:
         break;
       case tok::kw_if:
       case tok::kw_while:
-        if (CurrentToken->is(tok::l_paren)) {
+        if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) {
           next();
           if (!parseParens(/*LookForDecls=*/true))
             return false;
@@ -1088,7 +1088,7 @@ public:
         Tok->Type = TT_BinaryOperator;
         break;
       case tok::kw_operator:
-        if (CurrentToken->is(tok::l_paren)) {
+        if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) {
           CurrentToken->Type = TT_OverloadedOperator;
           next();
           if (CurrentToken != NULL && CurrentToken->is(tok::r_paren)) {
index c1c1696..fb5221e 100644 (file)
@@ -1679,11 +1679,16 @@ TEST_F(FormatTest, BlockComments) {
                    "/* */someCall(parameter);", getLLVMStyleWithColumns(15)));
 }
 
-TEST_F(FormatTest, Fuck) {
+TEST_F(FormatTest, FormatStarDependingOnContext) {
   verifyFormat("void f(int *a);");
   verifyFormat("void f() { f(fint * b); }");
 }
 
+TEST_F(FormatTest, SpecialTokensAtEndOfLine) {
+  verifyFormat("while");
+  verifyFormat("operator");
+}
+
 //===----------------------------------------------------------------------===//
 // Objective-C tests.
 //===----------------------------------------------------------------------===//