https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/178273
>From eff0ff383d8cb29958a87cf20a2c5ba30fd643c6 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk <[email protected]> Date: Tue, 27 Jan 2026 20:26:18 +0200 Subject: [PATCH 1/2] [Clang] prevent preprocessor crash on incomplete scoped __has_cpp_attribute arguments --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Lex/PPMacroExpansion.cpp | 2 +- clang/test/Preprocessor/has_attribute_errors.cpp | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index d03211a200a29..a1a97492f6783 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -175,6 +175,7 @@ Bug Fixes in This Version - Fixed a failed assertion in the preprocessor when ``__has_embed`` parameters are missing parentheses. (#GH175088) - Fix lifetime extension of temporaries in for-range-initializers in templates. (#GH165182) +- Fixed a preprocessor crash in ``__has_cpp_attribute`` on incomplete scoped attributes. (#GH178098) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 5efa4b5b3f872..734969e46e400 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1364,7 +1364,7 @@ static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS, Token ResultTok; bool SuppressDiagnostic = false; - while (true) { + while (Tok.isNoneOf(tok::eod, tok::eof)) { // Parse next token. if (ExpandArgs) PP.Lex(Tok); diff --git a/clang/test/Preprocessor/has_attribute_errors.cpp b/clang/test/Preprocessor/has_attribute_errors.cpp index 1fc88d3f926fb..d7492ed3f4a2c 100644 --- a/clang/test/Preprocessor/has_attribute_errors.cpp +++ b/clang/test/Preprocessor/has_attribute_errors.cpp @@ -14,3 +14,13 @@ __has_cpp_attribute(__clang__::fallthrough) // expected-error {{missing ')' afte // expected-note {{to match this '('}} \ // expected-error {{builtin feature check macro requires a parenthesized identifier}} +namespace GH178098 { +// expected-error@+2 {{builtin feature check macro requires a parenthesized identifier}} +// expected-error@+1 {{expected value in expression}} +#if __has_cpp_attribute(clang:: +#endif + +// expected-error@+3 {{builtin feature check macro requires a parenthesized identifier}} +// expected-error@+2 {{unterminated function-like macro invocation}} +__has_cpp_attribute(clang:: +} >From 1ecc84c206ac71f18e22784b89cafe9dba672b41 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk <[email protected]> Date: Tue, 27 Jan 2026 20:49:52 +0200 Subject: [PATCH 2/2] fix formatting --- clang/lib/Lex/PPMacroExpansion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 734969e46e400..350bd6c88eaad 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1443,7 +1443,7 @@ static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS, PP.Diag(LParenLoc, diag::note_matching) << tok::l_paren; SuppressDiagnostic = true; } - } +} } /// Helper function to return the IdentifierInfo structure of a Token _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
