Skip to content

[clang-repl] Fix printing preprocessed tokens and macros #104964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions clang/lib/Frontend/PrintPreprocessedOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Interpreter/preprocessor.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading