r260211 - Fixed preprocessed output of the first token for pragmas.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 9 00:51:27 PST 2016


Author: abataev
Date: Tue Feb  9 02:51:26 2016
New Revision: 260211

URL: http://llvm.org/viewvc/llvm-project?rev=260211&view=rev
Log:
Fixed preprocessed output of the first token for pragmas.
Clang did not expanded macros in the very first token of the pragmas
during preprocessed output

Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/test/Preprocessor/macro_expand.c

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=260211&r1=260210&r2=260211&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Feb  9 02:51:26 2016
@@ -573,6 +573,15 @@ struct UnknownPragmaHandler : public Pra
                     Token &PragmaTok) override {
     // Figure out what line we went to and insert the appropriate number of
     // newline characters.
+    if (ShouldExpandTokens) {
+      // The first token does not have expanded macros. Expand them, if
+      // required.
+      Token Toks[] = {PragmaTok};
+      PP.EnterTokenStream(Toks, llvm::array_lengthof(Toks),
+                          /*DisableMacroExpansion=*/false,
+                          /*OwnsTokens=*/false);
+      PP.Lex(PragmaTok);
+    }
     Callbacks->startNewLineIfNeeded();
     Callbacks->MoveToLine(PragmaTok.getLocation());
     Callbacks->OS.write(Prefix, strlen(Prefix));

Modified: cfe/trunk/test/Preprocessor/macro_expand.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro_expand.c?rev=260211&r1=260210&r2=260211&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/macro_expand.c (original)
+++ cfe/trunk/test/Preprocessor/macro_expand.c Tue Feb  9 02:51:26 2016
@@ -19,3 +19,9 @@ C: for(for))
 // rdar://6880648
 #define f(x,y...) y
 f()
+
+// CHECK: #pragma omp parallel for
+#define FOO parallel
+#define Streaming _Pragma("omp FOO for")
+Streaming
+




More information about the cfe-commits mailing list