Author: dblaikie Date: Wed Nov 14 19:04:21 2018 New Revision: 346928 URL: http://llvm.org/viewvc/llvm-project?rev=346928&view=rev Log: Fix combining pragma __debug dump & parser_crash with -E
Previously these would be transformed into annotation tokens and the preprocessor would then assume they were real tokens with source locations and assert/UB. Other pragmas that produce annotation tokens aren't a problem because they aren't handled if the parser isn't hooked up - ParsePragma.cpp registers those handlers & isn't run for pure preprocessing. So they're treated as unknown pragmas & printed verbatim by the preprocessor. Perhaps these pragmas should be treated the same way? But they got mixed in with other __debug pragmas that do need to be handled during preprocessing. The third __debug pragma that produces an annotation token is 'captured' - which had its own fix for this issue - by not inserting the annotation token in the first place if it detected that it was in preprocessing mode. I've removed that fix (from Lex/Pragma.cpp) in favor of the more general one in Frontend/PrintPreprocessedOutput.cpp. Added: cfe/trunk/test/Preprocessor/pragma.c Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp cfe/trunk/lib/Lex/Pragma.cpp Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=346928&r1=346927&r2=346928&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original) +++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Nov 14 19:04:21 2018 @@ -750,6 +750,11 @@ static void PrintPreprocessedTokens(Prep reinterpret_cast<Module *>(Tok.getAnnotationValue())); PP.Lex(Tok); continue; + } else if (Tok.isAnnotation()) { + // Ignore annotation tokens created by pragmas - the pragmas themselves + // will be reproduced in the preprocessed output. + PP.Lex(Tok); + continue; } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) { OS << II->getName(); } else if (Tok.isLiteral() && !Tok.needsCleaning() && Modified: cfe/trunk/lib/Lex/Pragma.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=346928&r1=346927&r2=346928&view=diff ============================================================================== --- cfe/trunk/lib/Lex/Pragma.cpp (original) +++ cfe/trunk/lib/Lex/Pragma.cpp Wed Nov 14 19:04:21 2018 @@ -1130,10 +1130,6 @@ struct PragmaDebugHandler : public Pragm } void HandleCaptured(Preprocessor &PP) { - // Skip if emitting preprocessed output. - if (PP.isPreprocessedOutput()) - return; - Token Tok; PP.LexUnexpandedToken(Tok); Added: cfe/trunk/test/Preprocessor/pragma.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma.c?rev=346928&view=auto ============================================================================== --- cfe/trunk/test/Preprocessor/pragma.c (added) +++ cfe/trunk/test/Preprocessor/pragma.c Wed Nov 14 19:04:21 2018 @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -E %s | FileCheck %s + +#pragma clang __debug parser_crash +#pragma clang __debug dump Test + +// CHECK: #pragma clang __debug parser_crash +// FIXME: The dump parameter is dropped. +// CHECK: #pragma clang __debug dump{{$}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits