[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)
Yutong Zhu via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 9 10:24:00 PST 2025
https://github.com/YutongZhuu updated https://github.com/llvm/llvm-project/pull/125370
>From 380ae2020f71cc5006db2e29b0a69f61297f585c 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/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/JumpDiagnostics.cpp | 17 +++++++----------
.../stmt.stmt/stmt.select/stmt.switch/p4.cpp | 11 +++++++++++
3 files changed, 20 insertions(+), 10 deletions(-)
create mode 100644 clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4410b9f99e802f7..fc11f213b2be10e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -733,6 +733,8 @@ Improvements to Clang's diagnostics
scope.Unlock();
require(scope); // Warning! Requires mu1.
}
+
+- Clang now forces attributes to not be scope parents (#84072).
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp
index d465599450e7ffc..c5577e09a86a1c3 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -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,7 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
Next = SC->getSubStmt();
else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
Next = LS->getSubStmt();
- else
+ else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
+ if (GetMustTailAttr(AS)) {
+ LabelAndGotoScopes[AS] = ParentScope;
+ MustTailStmts.push_back(AS);
+ }
+ Next = AS->getSubStmt();
+ } else
break;
LabelAndGotoScopes[SubStmt] = ParentScope;
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
new file mode 100644
index 000000000000000..d89dda7215074f7
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -fsyntax-only -std=c++20 -Xclang -verify %s
+
+void Func(int x) {
+ switch (x) {
+ [[likely]] case 0:
+ case 1:
+ int i = 3; // expected-note {{jump bypasses variable initialization}}
+ case 2: // expected-error {{cannot jump from switch statement to this case label}}
+ break;
+ }
+}
>From a47f6c1710600ece997a435c0ddd05c6935eea97 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <y25zhu at uwaterloo.ca>
Date: Fri, 7 Feb 2025 22:13:55 -0500
Subject: [PATCH 2/2] Fix test
---
clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
index d89dda7215074f7..e816da18036943a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang++ -fsyntax-only -std=c++20 -Xclang -verify %s
+// RUN: %clang -fsyntax-only -std=c++20 -Xclang -verify %s
void Func(int x) {
switch (x) {
More information about the cfe-commits
mailing list