From: Richard Smith Date: Wed, 13 Jun 2012 19:02:56 +0000 (+0000) Subject: Fix issue where a token paste which forms a /* or // would discard the rest of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5f7459b2d60ad55ed2ab3cfd281d9c718f5a8df;p=clang Fix issue where a token paste which forms a /* or // would discard the rest of 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 --- diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index 696754c741..81c9d0ab7a 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -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 diff --git a/test/Preprocessor/macro_paste_c_block_comment.c b/test/Preprocessor/macro_paste_c_block_comment.c index c690a4c7c9..92b2f60188 100644 --- a/test/Preprocessor/macro_paste_c_block_comment.c +++ b/test/Preprocessor/macro_paste_c_block_comment.c @@ -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 index 0000000000..457e6f7fc1 --- /dev/null +++ b/test/Preprocessor/macro_paste_identifier_error.c @@ -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;