[clang] [clang] Fix assertion failure in `injectEmbedTokens` (PR #99624)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 03:00:06 PDT 2024
https://github.com/Fznamznon created https://github.com/llvm/llvm-project/pull/99624
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.
>From 4922e1d4de5ccc9e645b151eb923440573e85fae Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" <mariya.podchishchaeva at intel.com>
Date: Fri, 19 Jul 2024 02:56:38 -0700
Subject: [PATCH] [clang] Fix assertion failure in `injectEmbedTokens`
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.
---
clang/lib/Parse/ParseExpr.cpp | 2 +-
clang/test/Preprocessor/embed_weird.cpp | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..a12c375c8d48c 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3597,7 +3597,7 @@ void Parser::injectEmbedTokens() {
I += 2;
}
PP.EnterTokenStream(std::move(Toks), /*DisableMacroExpansion=*/true,
- /*IsReinject=*/false);
+ /*IsReinject=*/true);
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
}
diff --git a/clang/test/Preprocessor/embed_weird.cpp b/clang/test/Preprocessor/embed_weird.cpp
index cc73a88e5a657..f533230111b43 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -115,3 +115,11 @@ void f1() {
};
}
#endif
+
+static_assert(_Generic(
+#embed __FILE__ limit(1)
+ , int : 1, default : 0));
+
+static_assert(alignof(typeof(
+#embed __FILE__ limit(1)
+)) == alignof(int));
More information about the cfe-commits
mailing list