[clang] [clang][Preprocessor] Fix expansion locations for feature-like builtin macros (PR #207130)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 9 06:20:08 PDT 2026


================
@@ -552,6 +552,25 @@ file './input.cpp'
   }
 }
 
+TEST_F(TokenCollectorTest, FeatureLikeBuiltinMacros) {
+  recordTokens("__has_builtin(__builtin_allow_runtime_check)\n");
+  EXPECT_THAT(Buffer.expandedTokens(),
+              ElementsAre(AllOf(Kind(tok::numeric_constant), HasText("1")),
+                          Kind(tok::eof)));
+  auto ExpansionRange =
+      SourceMgr->getExpansionRange(findExpanded("1").front().location());
+  auto MacroInvocation =
+      findSpelled("__has_builtin ( __builtin_allow_runtime_check )");
+  EXPECT_EQ(MacroInvocation.front().location(), ExpansionRange.getBegin());
+  EXPECT_EQ(MacroInvocation.back().location(), ExpansionRange.getEnd());
+
+  AllowErrors = true;
+  recordTokens("__is_identifier;\n");
+  EXPECT_THAT(Buffer.expandedTokens(),
+              ElementsAre(AllOf(Kind(tok::numeric_constant), HasText("0")),
+                          Kind(tok::eof)));
----------------
AaronBallman wrote:

I think this test can likely be removed given that it's not testing locations (it's just a "demonstrate we don't crash" test I believe, but the other test also covers that need).

https://github.com/llvm/llvm-project/pull/207130


More information about the cfe-commits mailing list