https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/137880
>From be6d7e3fcf4ef53bdf0dce7ff1b541f9de33c81f Mon Sep 17 00:00:00 2001 From: erichkeane <eke...@nvidia.com> Date: Tue, 29 Apr 2025 14:32:32 -0700 Subject: [PATCH 1/2] Fix crash when an attribute is applied to pragma attribute/pragma dump 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 --- clang/lib/Parse/ParseStmt.cpp | 4 ++++ clang/test/Parser/gh137861.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 clang/test/Parser/gh137861.cpp diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 4e801f4ef890f..97924f093240f 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@+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@+1{{an attribute list cannot appear here}} +__attribute__((aligned(64))) +#pragma clang __debug dump foo +} + +void foo3() { + // expected-error@+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@+1{{an attribute list cannot appear here}} + [[nodiscard]] +#pragma clang __debug dump foo +} >From 5411b1fb7ea982898b29bdfbe59faaab390e7bb9 Mon Sep 17 00:00:00 2001 From: erichkeane <eke...@nvidia.com> Date: Wed, 30 Apr 2025 06:26:27 -0700 Subject: [PATCH 2/2] add release note --- clang/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3105d8b481560..8f6a191c6a375 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -471,6 +471,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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits