[PATCH] D155342: [clang][JumpDiagnostics] ignore non-asm goto target scopes
Nick Desaulniers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 14 15:17:25 PDT 2023
nickdesaulniers updated this revision to Diff 540574.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.
- add link to CBL
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155342/new/
https://reviews.llvm.org/D155342
Files:
clang/lib/Sema/JumpDiagnostics.cpp
clang/test/Sema/asm-goto.cpp
Index: clang/test/Sema/asm-goto.cpp
===================================================================
--- clang/test/Sema/asm-goto.cpp
+++ clang/test/Sema/asm-goto.cpp
@@ -59,3 +59,13 @@
loop:
return 0;
}
+
+void test4cleanup(int*);
+// No errors expected.
+void test4(void) {
+ asm goto(""::::l0);
+l0:;
+ int x __attribute__((cleanup(test4cleanup)));
+ asm goto(""::::l1);
+l1:;
+}
Index: clang/lib/Sema/JumpDiagnostics.cpp
===================================================================
--- clang/lib/Sema/JumpDiagnostics.cpp
+++ clang/lib/Sema/JumpDiagnostics.cpp
@@ -370,7 +370,7 @@
// have it. This makes the second scan not have to walk the AST again.
LabelAndGotoScopes[S] = ParentScope;
AsmJumps.push_back(GS);
- for (auto *E : GS->labels())
+ for (AddrLabelExpr *E : GS->labels())
AsmJumpTargets.push_back(E->getLabel());
}
break;
@@ -788,6 +788,17 @@
// Walk through all the jump sites, checking that they can trivially
// reach this label scope.
for (auto [JumpScope, JumpStmt] : JumpScopes) {
+ // This unnecessary copy is because:
+ // warning: captured structured bindings are a C++20 extension
+ // [-Wc++20-extensions]
+ LabelDecl *TL = TargetLabel;
+ // Is TargetLabel one of the targets of the JumpStmt? If not, then skip
+ // it.
+ if (IsAsmGoto &&
+ llvm::none_of(cast<GCCAsmStmt>(JumpStmt)->labels(),
+ [=](AddrLabelExpr *E) { return E->getLabel() == TL; }))
+ continue;
+
unsigned Scope = JumpScope;
// Walk out the "scope chain" for this scope, looking for a scope
// we've marked reachable. For well-formed code this amortizes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155342.540574.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230714/3bf1a7cc/attachment.bin>
More information about the cfe-commits
mailing list