[clang] 84a5435 - Fix crash when an attribute is applied to pragma attribute/pragma dump (#137880)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 30 07:31:46 PDT 2025
Author: Erich Keane
Date: 2025-04-30T07:31:42-07:00
New Revision: 84a5435db63f43ec3f4abbb42eda2674dd35cda9
URL: https://github.com/llvm/llvm-project/commit/84a5435db63f43ec3f4abbb42eda2674dd35cda9
DIFF: https://github.com/llvm/llvm-project/commit/84a5435db63f43ec3f4abbb42eda2674dd35cda9.diff
LOG: Fix crash when an attribute is applied to pragma attribute/pragma dump (#137880)
These two don't result in a statement, so the attempt to apply the
attributes to them was crashing. This patch correctly prohibits the use
of attributes on these clauses.
Fixes: #137861
Added:
clang/test/Parser/gh137861.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseStmt.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1adb59a970329..5cc1a36fac1e8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -511,6 +511,9 @@ Bug Fixes in This Version
evaluation. The crashes were happening during diagnostics emission due to
unimplemented statement printer. (#GH132641)
- Fixed visibility calculation for template functions. (#GH103477)
+- Fixed a bug where an attribute before a ``pragma clang attribute`` or
+ ``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
+ the invalid attribute location appropriately. (#GH137861)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index bdd02469a85bb..546e524932f5e 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -526,10 +526,14 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
return ParsePragmaLoopHint(Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs);
case tok::annot_pragma_dump:
+ ProhibitAttributes(CXX11Attrs);
+ ProhibitAttributes(GNUAttrs);
HandlePragmaDump();
return StmtEmpty();
case tok::annot_pragma_attribute:
+ ProhibitAttributes(CXX11Attrs);
+ ProhibitAttributes(GNUAttrs);
HandlePragmaAttribute();
return StmtEmpty();
}
diff --git a/clang/test/Parser/gh137861.cpp b/clang/test/Parser/gh137861.cpp
new file mode 100644
index 0000000000000..9354aef919650
--- /dev/null
+++ b/clang/test/Parser/gh137861.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -verify
+
+void foo() {
+ // expected-error at +1{{an attribute list cannot appear here}}
+__attribute__((aligned(64)))
+#pragma clang attribute push(__attribute__((uninitialized)), apply_to = any(variable(is_local)))
+{
+ int f;
+}
+#pragma clang attribute pop
+}
+
+void foo2() {
+ // expected-error at +1{{an attribute list cannot appear here}}
+__attribute__((aligned(64)))
+#pragma clang __debug dump foo
+}
+
+void foo3() {
+ // expected-error at +1{{an attribute list cannot appear here}}
+ [[nodiscard]]
+#pragma clang attribute push(__attribute__((uninitialized)), apply_to = any(variable(is_local)))
+{
+ int f;
+}
+#pragma clang attribute pop
+}
+
+void foo4() {
+ // expected-error at +1{{an attribute list cannot appear here}}
+ [[nodiscard]]
+#pragma clang __debug dump foo
+}
More information about the cfe-commits
mailing list