[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());
+
----------------
AaronBallman wrote:

This seems a bit odd to me; the `MacroInvocation` variable is tracking tokens with extra whitespaces, but it's comparing against `ExpansionRange` which does not have that whitespace. So I wouldn't have expected these locations to be the same, which suggests I'm misundstanding something (or there's a bug).

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


More information about the cfe-commits mailing list