]> granicus.if.org Git - clang/commitdiff
Fix combining pragma __debug dump & parser_crash with -E
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Nov 2018 03:04:21 +0000 (03:04 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Nov 2018 03:04:21 +0000 (03:04 +0000)
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.

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

lib/Frontend/PrintPreprocessedOutput.cpp
lib/Lex/Pragma.cpp
test/Preprocessor/pragma.c [new file with mode: 0644]

index 69cd072ea57f4fd58491faa1ffb1e944910a07fc..3b835985a54c056a7cabb598cfa3dbd197d36fc8 100644 (file)
@@ -750,6 +750,11 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
           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() &&
index 0a63ed724cf6b6cdb675bf75c4f58b5c6a886f2a..e58378f6ab32217d11b9cf55d93d5932b3223bbb 100644 (file)
@@ -1130,10 +1130,6 @@ struct PragmaDebugHandler : public PragmaHandler {
   }
 
   void HandleCaptured(Preprocessor &PP) {
-    // Skip if emitting preprocessed output.
-    if (PP.isPreprocessedOutput())
-      return;
-
     Token Tok;
     PP.LexUnexpandedToken(Tok);
 
diff --git a/test/Preprocessor/pragma.c b/test/Preprocessor/pragma.c
new file mode 100644 (file)
index 0000000..b491632
--- /dev/null
@@ -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{{$}}