]> granicus.if.org Git - clang/commitdiff
Fix issue where a token paste which forms a /* or // would discard the rest of
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 13 Jun 2012 19:02:56 +0000 (19:02 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 13 Jun 2012 19:02:56 +0000 (19:02 +0000)
the input: token-pasting was producing a tok::eof.

Patch by Andy Gibbs!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158412 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/TokenLexer.cpp
test/Preprocessor/macro_paste_c_block_comment.c
test/Preprocessor/macro_paste_identifier_error.c [new file with mode: 0644]

index 696754c74167fc42b63a6ce69839f6c8e7abb026..81c9d0ab7ae297fb39d98a345366afb35360e00c 100644 (file)
@@ -568,8 +568,8 @@ bool TokenLexer::PasteTokens(Token &Tok) {
             << Buffer.str();
         }
 
-        // Do not consume the RHS.
-        --CurToken;
+        // An error has occurred so exit loop.
+        break;
       }
 
       // Turn ## into 'unknown' to avoid # ## # from looking like a paste
index c690a4c7c9f57d129d9cf0758e31e61586b5bb41..92b2f60188529228db3a581688c10be9efcf8ec7 100644 (file)
@@ -3,3 +3,6 @@
 #define COMM / ## *
 COMM // expected-error {{pasting formed '/*', an invalid preprocessing token}}
 
+// Demonstrate that an invalid preprocessing token
+// doesn't swallow the rest of the file...
+#error EOF // expected-error {{EOF}}
diff --git a/test/Preprocessor/macro_paste_identifier_error.c b/test/Preprocessor/macro_paste_identifier_error.c
new file mode 100644 (file)
index 0000000..457e6f7
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fms-extensions -Wno-invalid-token-paste %s -verify
+// RUN: %clang_cc1 -E -fms-extensions -Wno-invalid-token-paste %s | FileCheck %s
+// RUN: %clang_cc1 -E -fms-extensions -Wno-invalid-token-paste -x assembler-with-cpp %s | FileCheck %s
+
+#define foo a ## b ## = 0
+int foo;
+// CHECK: int ab = 0;