[clang] 20d3815 - [clang] Fix assertion failure in `injectEmbedTokens` (#99624)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 22 01:46:33 PDT 2024


Author: Mariya Podchishchaeva
Date: 2024-07-22T10:46:29+02:00
New Revision: 20d38158ffbe1e01b74e39d36d4b3bc5e7a63d66

URL: https://github.com/llvm/llvm-project/commit/20d38158ffbe1e01b74e39d36d4b3bc5e7a63d66
DIFF: https://github.com/llvm/llvm-project/commit/20d38158ffbe1e01b74e39d36d4b3bc5e7a63d66.diff

LOG: [clang] Fix assertion failure in `injectEmbedTokens` (#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.

Added: 
    

Modified: 
    clang/lib/Parse/ParseExpr.cpp
    clang/test/Preprocessor/embed_weird.cpp

Removed: 
    


################################################################################
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 6eb2923152f15..90180e2d3cc70 100644
--- a/clang/test/Preprocessor/embed_weird.cpp
+++ b/clang/test/Preprocessor/embed_weird.cpp
@@ -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;
 };


        


More information about the cfe-commits mailing list