Skip to content

Commit 947b9f5

Browse files
authored
[clang-repl] Fix printing preprocessed tokens and macros (#104964)
1 parent a3d4187 commit 947b9f5

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clang/lib/Frontend/PrintPreprocessedOutput.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
916916
PP.Lex(Tok);
917917
continue;
918918
} else if (Tok.is(tok::annot_repl_input_end)) {
919-
PP.Lex(Tok);
920-
continue;
919+
// Fall through to exit the loop.
921920
} else if (Tok.is(tok::eod)) {
922921
// Don't print end of directive tokens, since they are typically newlines
923922
// that mess up our line tracking. These come from unknown pre-processor
@@ -1025,7 +1024,8 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
10251024
Callbacks->setEmittedTokensOnThisLine();
10261025
IsStartOfLine = false;
10271026

1028-
if (Tok.is(tok::eof)) break;
1027+
if (Tok.is(tok::eof) || Tok.is(tok::annot_repl_input_end))
1028+
break;
10291029

10301030
PP.Lex(Tok);
10311031
// 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) {
10481048
// the macro table at the end.
10491049
PP.EnterMainSourceFile();
10501050

1051-
Token Tok;
1052-
do PP.Lex(Tok);
1053-
while (Tok.isNot(tok::eof));
1051+
PP.LexTokensUntilEOF();
10541052

10551053
SmallVector<id_macro_pair, 128> MacrosByID;
10561054
for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %clang_cc1 -fincremental-extensions -E %s
2+
// RUN: %clang_cc1 -fincremental-extensions -E -dD %s
3+
// RUN: %clang_cc1 -fincremental-extensions -E -dI %s
4+
// RUN: %clang_cc1 -fincremental-extensions -E -dM %s

0 commit comments

Comments
 (0)