[PATCH] D125177: Recognize scope of thread local variables in CFGBuilder
Krzysztof Parzyszek via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 8 08:20:09 PDT 2022
kparzysz updated this revision to Diff 427939.
kparzysz added a comment.
Use the proper diff file this time.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125177/new/
https://reviews.llvm.org/D125177
Files:
clang/lib/Analysis/CFG.cpp
clang/test/Analysis/cfg.cpp
Index: clang/test/Analysis/cfg.cpp
===================================================================
--- clang/test/Analysis/cfg.cpp
+++ clang/test/Analysis/cfg.cpp
@@ -593,6 +593,63 @@
A(), B();
}
+// CHECK-LABEL: int crash_with_thread_local(char *p, int *q)
+// CHECK: [B7 (ENTRY)]
+// CHECK-NEXT: Succs (1): B6
+// CHECK: [B1]
+// CHECK-NEXT: bail:
+// CHECK-NEXT: 1: 0
+// CHECK-NEXT: 2: return [B1.1];
+// CHECK-NEXT: Preds (2): B2 B5
+// CHECK-NEXT: Succs (1): B0
+// CHECK: [B2]
+// CHECK-NEXT: 1: 0
+// CHECK-NEXT: 2: q
+// CHECK-NEXT: 3: [B2.2] (ImplicitCastExpr, LValueToRValue, int *)
+// CHECK-NEXT: 4: *[B2.3]
+// CHECK-NEXT: 5: [B2.4] = [B2.1]
+// CHECK-NEXT: Preds (2): B3 B4
+// CHECK-NEXT: Succs (1): B1
+// CHECK: [B3]
+// WARNINGS-NEXT: 1: (CXXConstructExpr, struct ClassWithDtor)
+// ANALYZER-NEXT: 1: (CXXConstructExpr, [B3.2], struct ClassWithDtor)
+// CHECK-NEXT: 2: thread_local ClassWithDtor a;
+// CHECK-NEXT: Preds (1): B4
+// CHECK-NEXT: Succs (1): B2
+// CHECK: [B4]
+// CHECK-NEXT: T: static init a
+// CHECK-NEXT: Preds (1): B6
+// CHECK-NEXT: Succs (2): B2 B3
+// CHECK: [B5]
+// CHECK-NEXT: T: goto bail;
+// CHECK-NEXT: Preds (1): B6
+// CHECK-NEXT: Succs (1): B1
+// CHECK: [B6]
+// CHECK-NEXT: 1: p
+// CHECK-NEXT: 2: [B6.1] (ImplicitCastExpr, LValueToRValue, char *)
+// CHECK-NEXT: 3: 0
+// CHECK-NEXT: 4: [B6.3] (ImplicitCastExpr, NullToPointer, char *)
+// CHECK-NEXT: 5: [B6.2] != [B6.4]
+// CHECK-NEXT: T: if [B6.5]
+// CHECK-NEXT: Preds (1): B7
+// CHECK-NEXT: Succs (2): B5 B4
+// CHECK: [B0 (EXIT)]
+// CHECK-NEXT: Preds (1): B1
+
+struct ClassWithDtor {
+ ~ClassWithDtor() {}
+};
+
+int crash_with_thread_local(char *p, int *q) {
+ if (p != 0) {
+ goto bail;
+ }
+ thread_local ClassWithDtor a;
+ *q = 0;
+bail:
+ return 0;
+}
+
// CHECK-LABEL: template<> int *PR18472<int>()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT: Succs (1): B1
Index: clang/lib/Analysis/CFG.cpp
===================================================================
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2019,13 +2019,8 @@
return Scope;
// Check if variable is local.
- switch (VD->getStorageClass()) {
- case SC_None:
- case SC_Auto:
- case SC_Register:
- break;
- default: return Scope;
- }
+ if (!VD->hasLocalStorage())
+ return Scope;
if (BuildOpts.AddImplicitDtors) {
if (!hasTrivialDestructor(VD) || BuildOpts.AddScopes) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125177.427939.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220508/0c047751/attachment-0001.bin>
More information about the cfe-commits
mailing list