Skip to content

Commit 7a95495

Browse files
hahnjodevajithvs
authored andcommitted
UPSTREAM: [clang-repl] Fix printing preprocessed tokens and macros (llvm#104964)
(cherry picked from commit 947b9f5)
1 parent 0f33f53 commit 7a95495

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
@@ -833,8 +833,7 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
833833
PP.Lex(Tok);
834834
continue;
835835
} else if (Tok.is(tok::annot_repl_input_end)) {
836-
PP.Lex(Tok);
837-
continue;
836+
// Fall through to exit the loop.
838837
} else if (Tok.is(tok::eod)) {
839838
// Don't print end of directive tokens, since they are typically newlines
840839
// that mess up our line tracking. These come from unknown pre-processor
@@ -922,7 +921,8 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
922921
Callbacks->setEmittedTokensOnThisLine();
923922
IsStartOfLine = false;
924923

925-
if (Tok.is(tok::eof)) break;
924+
if (Tok.is(tok::eof) || Tok.is(tok::annot_repl_input_end))
925+
break;
926926

927927
PP.Lex(Tok);
928928
}
@@ -941,9 +941,7 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
941941
// the macro table at the end.
942942
PP.EnterMainSourceFile();
943943

944-
Token Tok;
945-
do PP.Lex(Tok);
946-
while (Tok.isNot(tok::eof));
944+
PP.LexTokensUntilEOF();
947945

948946
SmallVector<id_macro_pair, 128> MacrosByID;
949947
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)