https://github.com/yronglin created https://github.com/llvm/llvm-project/pull/149982
Fixes https://github.com/llvm/llvm-project/issues/149762. >From d7f00bde68176aab93d4da50a12aea00c29d5276 Mon Sep 17 00:00:00 2001 From: yronglin <yronglin...@gmail.com> Date: Tue, 22 Jul 2025 17:18:36 +0800 Subject: [PATCH] [clang] Check empty macro name in #pragma push_macro("") or #pragma pop_macro("") Signed-off-by: yronglin <yronglin...@gmail.com> --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Lex/Pragma.cpp | 4 ++++ clang/test/Preprocessor/pragma-pushpop-macro.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 81483c12c8fe9..461902701bc48 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -814,6 +814,8 @@ Bug Fixes in This Version - Fixed a failed assertion with an operator call expression which comes from a macro expansion when performing analysis for nullability attributes. (#GH138371) - Fixed a concept equivalent checking crash due to untransformed constraint expressions. (#GH146614) +- Fix a crash when marco name is empty in ``#pragma push_macro("")`` or + ``#pragma pop_macro("")``. (GH149762). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 01c85e6ad95d5..7f1190c4dcce6 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -604,6 +604,10 @@ IdentifierInfo *Preprocessor::ParsePragmaPushOrPopMacro(Token &Tok) { assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' && "Invalid string token!"); + // FIXME: Should we emit a warning? + if (StrVal.size() <= 2) + return nullptr; + // Create a Token from the string. Token MacroTok; MacroTok.startToken(); diff --git a/clang/test/Preprocessor/pragma-pushpop-macro.c b/clang/test/Preprocessor/pragma-pushpop-macro.c index 0aee074c55c77..238e3ed5eddb3 100644 --- a/clang/test/Preprocessor/pragma-pushpop-macro.c +++ b/clang/test/Preprocessor/pragma-pushpop-macro.c @@ -56,3 +56,6 @@ int P; // CHECK: int pmy2 = 4 // CHECK: int Q; // CHECK: int P; + +#pragma push_macro("") +#pragma pop_macro("") _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits