[clang] [clang] Check empty macro name in `#pragma push_macro("")` or `#pragma pop_macro("")` (PR #149982)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 02:21:08 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (yronglin)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/149762.
---
Full diff: https://github.com/llvm/llvm-project/pull/149982.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Lex/Pragma.cpp (+4)
- (modified) clang/test/Preprocessor/pragma-pushpop-macro.c (+3)
``````````diff
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("")
``````````
</details>
https://github.com/llvm/llvm-project/pull/149982
More information about the cfe-commits
mailing list