[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
Yutong Zhu via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 1 17:17:33 PST 2025
https://github.com/YutongZhuu created https://github.com/llvm/llvm-project/pull/125370
This PR addresses https://github.com/llvm/llvm-project/issues/84072.
>From 01497e746ae23ea5033b1c6cd6f9f9718d6dc3d6 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Sat, 1 Feb 2025 20:09:13 -0500
Subject: [PATCH 1/2] Force AttributedStmtClass to not be scope parents
---
clang/lib/Sema/JumpDiagnostics.cpp | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index d465599450e7ffc..68a7049185b32ff 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -310,8 +310,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
unsigned &ParentScope = ((isa<Expr>(S) && !isa<StmtExpr>(S))
? origParentScope : independentParentScope);
- unsigned StmtsToSkip = 0u;
-
+ unsigned StmtsToSkip = 0u;
+
// If we found a label, remember that it is in ParentScope scope.
switch (S->getStmtClass()) {
case Stmt::AddrLabelExprClass:
@@ -597,15 +597,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
LabelAndGotoScopes[S] = ParentScope;
break;
- case Stmt::AttributedStmtClass: {
- AttributedStmt *AS = cast<AttributedStmt>(S);
- if (GetMustTailAttr(AS)) {
- LabelAndGotoScopes[AS] = ParentScope;
- MustTailStmts.push_back(AS);
- }
- break;
- }
-
case Stmt::OpenACCComputeConstructClass: {
unsigned NewParentScope = Scopes.size();
OpenACCComputeConstruct *CC = cast<OpenACCComputeConstruct>(S);
@@ -658,6 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
Next = SC->getSubStmt();
else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
Next = LS->getSubStmt();
+ else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)){
+ if (GetMustTailAttr(AS)) {
+ LabelAndGotoScopes[AS] = ParentScope;
+ MustTailStmts.push_back(AS);
+ }
+ Next = AS->getSubStmt();
+ }
else
break;
@@ -945,7 +943,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
unsigned FromScope = LabelAndGotoScopes[From];
unsigned ToScope = LabelAndGotoScopes[To];
-
+
// Common case: exactly the same scope, which is fine.
if (FromScope == ToScope) return;
>From e71018ffee1be8cd26ee2ac22f226152ea385998 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Sat, 1 Feb 2025 20:13:41 -0500
Subject: [PATCH 2/2] Clang-format
---
clang/lib/Sema/JumpDiagnostics.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index 68a7049185b32ff..c5577e09a86a1c3 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -310,8 +310,8 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
unsigned &ParentScope = ((isa<Expr>(S) && !isa<StmtExpr>(S))
? origParentScope : independentParentScope);
- unsigned StmtsToSkip = 0u;
-
+ unsigned StmtsToSkip = 0u;
+
// If we found a label, remember that it is in ParentScope scope.
switch (S->getStmtClass()) {
case Stmt::AddrLabelExprClass:
@@ -649,14 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
Next = SC->getSubStmt();
else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
Next = LS->getSubStmt();
- else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)){
+ else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
if (GetMustTailAttr(AS)) {
LabelAndGotoScopes[AS] = ParentScope;
MustTailStmts.push_back(AS);
}
Next = AS->getSubStmt();
- }
- else
+ } else
break;
LabelAndGotoScopes[SubStmt] = ParentScope;
@@ -943,7 +942,7 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
unsigned FromScope = LabelAndGotoScopes[From];
unsigned ToScope = LabelAndGotoScopes[To];
-
+
// Common case: exactly the same scope, which is fine.
if (FromScope == ToScope) return;
More information about the cfe-commits
mailing list