Skip to content

Commit 380ae20

Browse files
committed
Force AttributedStmtClass to not be scope parents
1 parent f51db95 commit 380ae20

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ Improvements to Clang's diagnostics
733733
scope.Unlock();
734734
require(scope); // Warning! Requires mu1.
735735
}
736+
737+
- Clang now forces attributes to not be scope parents (#84072).
736738

737739
Improvements to Clang's time-trace
738740
----------------------------------

clang/lib/Sema/JumpDiagnostics.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
597597
LabelAndGotoScopes[S] = ParentScope;
598598
break;
599599

600-
case Stmt::AttributedStmtClass: {
601-
AttributedStmt *AS = cast<AttributedStmt>(S);
602-
if (GetMustTailAttr(AS)) {
603-
LabelAndGotoScopes[AS] = ParentScope;
604-
MustTailStmts.push_back(AS);
605-
}
606-
break;
607-
}
608-
609600
case Stmt::OpenACCComputeConstructClass: {
610601
unsigned NewParentScope = Scopes.size();
611602
OpenACCComputeConstruct *CC = cast<OpenACCComputeConstruct>(S);
@@ -658,7 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
658649
Next = SC->getSubStmt();
659650
else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
660651
Next = LS->getSubStmt();
661-
else
652+
else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
653+
if (GetMustTailAttr(AS)) {
654+
LabelAndGotoScopes[AS] = ParentScope;
655+
MustTailStmts.push_back(AS);
656+
}
657+
Next = AS->getSubStmt();
658+
} else
662659
break;
663660

664661
LabelAndGotoScopes[SubStmt] = ParentScope;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang++ -fsyntax-only -std=c++20 -Xclang -verify %s
2+
3+
void Func(int x) {
4+
switch (x) {
5+
[[likely]] case 0:
6+
case 1:
7+
int i = 3; // expected-note {{jump bypasses variable initialization}}
8+
case 2: // expected-error {{cannot jump from switch statement to this case label}}
9+
break;
10+
}
11+
}

0 commit comments

Comments
 (0)