Skip to content

Commit 84a5435

Browse files
authored
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
1 parent e8ae779 commit 84a5435

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ Bug Fixes in This Version
511511
evaluation. The crashes were happening during diagnostics emission due to
512512
unimplemented statement printer. (#GH132641)
513513
- Fixed visibility calculation for template functions. (#GH103477)
514+
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
515+
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
516+
the invalid attribute location appropriately. (#GH137861)
514517

515518
Bug Fixes to Compiler Builtins
516519
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Parse/ParseStmt.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,14 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
526526
return ParsePragmaLoopHint(Stmts, StmtCtx, TrailingElseLoc, CXX11Attrs);
527527

528528
case tok::annot_pragma_dump:
529+
ProhibitAttributes(CXX11Attrs);
530+
ProhibitAttributes(GNUAttrs);
529531
HandlePragmaDump();
530532
return StmtEmpty();
531533

532534
case tok::annot_pragma_attribute:
535+
ProhibitAttributes(CXX11Attrs);
536+
ProhibitAttributes(GNUAttrs);
533537
HandlePragmaAttribute();
534538
return StmtEmpty();
535539
}

clang/test/Parser/gh137861.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 %s -verify
2+
3+
void foo() {
4+
// expected-error@+1{{an attribute list cannot appear here}}
5+
__attribute__((aligned(64)))
6+
#pragma clang attribute push(__attribute__((uninitialized)), apply_to = any(variable(is_local)))
7+
{
8+
int f;
9+
}
10+
#pragma clang attribute pop
11+
}
12+
13+
void foo2() {
14+
// expected-error@+1{{an attribute list cannot appear here}}
15+
__attribute__((aligned(64)))
16+
#pragma clang __debug dump foo
17+
}
18+
19+
void foo3() {
20+
// expected-error@+1{{an attribute list cannot appear here}}
21+
[[nodiscard]]
22+
#pragma clang attribute push(__attribute__((uninitialized)), apply_to = any(variable(is_local)))
23+
{
24+
int f;
25+
}
26+
#pragma clang attribute pop
27+
}
28+
29+
void foo4() {
30+
// expected-error@+1{{an attribute list cannot appear here}}
31+
[[nodiscard]]
32+
#pragma clang __debug dump foo
33+
}

0 commit comments

Comments
 (0)