Skip to content

Commit

Permalink
[clang] Fix assertion failure in injectEmbedTokens (llvm#99624)
Browse files Browse the repository at this point in the history
It seems for C++ lexer has some caching ability which doesn't expect
injecting "new" tokens in the middle of the cache. Technically #embed
tokens are not completely new since they have already been read from the
file and there was #embed annotation token in this place, so set
`reinject` flag for them to silence assertion.
  • Loading branch information
Fznamznon authored and sgundapa committed Jul 23, 2024
1 parent d818470 commit 276e90a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3597,7 +3597,7 @@ void Parser::injectEmbedTokens() {
I += 2;
}
PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true,
/*IsReinject=*/false);
/*IsReinject=*/true);
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
}

Expand Down
8 changes: 8 additions & 0 deletions clang/test/Preprocessor/embed_weird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ void f1() {
}
#endif

static_assert(_Generic(
#embed __FILE__ limit(1)
, int : 1, default : 0));

static_assert(alignof(typeof(
#embed __FILE__ limit(1)
)) == alignof(int));

struct HasChar {
signed char ch;
};
Expand Down

0 comments on commit 276e90a

Please sign in to comment.