Skip to content

Commit be6d7e3

Browse files
committed
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
1 parent aa940ce commit be6d7e3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/Parse/ParseStmt.cpp

Lines changed: 4 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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)