[clang] 947b9f5 - [clang-repl] Fix printing preprocessed tokens and macros (#104964)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 21 00:09:11 PDT 2024


Author: Jonas Hahnfeld
Date: 2024-08-21T09:09:06+02:00
New Revision: 947b9f55b5f327e14368a48fb6ce10242ea29bf3

URL: https://github.com/llvm/llvm-project/commit/947b9f55b5f327e14368a48fb6ce10242ea29bf3
DIFF: https://github.com/llvm/llvm-project/commit/947b9f55b5f327e14368a48fb6ce10242ea29bf3.diff

LOG: [clang-repl] Fix printing preprocessed tokens and macros (#104964)

Added: 
    clang/test/Interpreter/preprocessor.cpp

Modified: 
    clang/lib/Frontend/PrintPreprocessedOutput.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 135dca0e6a1775..383d4356084916 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -916,8 +916,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
       PP.Lex(Tok);
       continue;
     } else if (Tok.is(tok::annot_repl_input_end)) {
-      PP.Lex(Tok);
-      continue;
+      // Fall through to exit the loop.
     } else if (Tok.is(tok::eod)) {
       // Don't print end of directive tokens, since they are typically newlines
       // that mess up our line tracking. These come from unknown pre-processor
@@ -1025,7 +1024,8 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
     Callbacks->setEmittedTokensOnThisLine();
     IsStartOfLine = false;
 
-    if (Tok.is(tok::eof)) break;
+    if (Tok.is(tok::eof) || Tok.is(tok::annot_repl_input_end))
+      break;
 
     PP.Lex(Tok);
     // If lexing that token causes us to need to skip future tokens, do so now.
@@ -1048,9 +1048,7 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
   // the macro table at the end.
   PP.EnterMainSourceFile();
 
-  Token Tok;
-  do PP.Lex(Tok);
-  while (Tok.isNot(tok::eof));
+  PP.LexTokensUntilEOF();
 
   SmallVector<id_macro_pair, 128> MacrosByID;
   for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();

diff  --git a/clang/test/Interpreter/preprocessor.cpp b/clang/test/Interpreter/preprocessor.cpp
new file mode 100644
index 00000000000000..8239fd45e661b0
--- /dev/null
+++ b/clang/test/Interpreter/preprocessor.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fincremental-extensions -E %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dD %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dI %s
+// RUN: %clang_cc1 -fincremental-extensions -E -dM %s


        


More information about the cfe-commits mailing list