Skip to content

Commit 032b78a

Browse files
committed
[analyzer] Revert the accidental commit of D82122
Was accidentally squished into rGb6cbe6cb0399d4671e5384dcc326af56bc6bd122. The assert fires on the code snippet included in this commit. More discussion can be found in https://reviews.llvm.org/D82598.
1 parent 9e81d8b commit 032b78a

File tree

2 files changed

+104
-9
lines changed

2 files changed

+104
-9
lines changed

clang/lib/StaticAnalyzer/Core/Environment.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,12 @@ EnvironmentManager::removeDeadBindings(Environment Env,
183183
F.getTreeFactory());
184184

185185
// Iterate over the block-expr bindings.
186-
for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
186+
for (Environment::iterator I = Env.begin(), E = Env.end();
187+
I != E; ++I) {
187188
const EnvironmentEntry &BlkExpr = I.getKey();
188189
const SVal &X = I.getData();
189190

190-
const bool IsBlkExprLive =
191-
SymReaper.isLive(BlkExpr.getStmt(), BlkExpr.getLocationContext());
192-
193-
assert((isa<Expr>(BlkExpr.getStmt()) || !IsBlkExprLive) &&
194-
"Only Exprs can be live, LivenessAnalysis argues about the liveness "
195-
"of *values*!");
196-
197-
if (IsBlkExprLive) {
191+
if (SymReaper.isLive(BlkExpr.getStmt(), BlkExpr.getLocationContext())) {
198192
// Copy the binding to the new map.
199193
EBMapRef = EBMapRef.add(BlkExpr, X);
200194

clang/test/Analysis/live-stmts.mm

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// RUN: %clang_analyze_cc1 -w -fblocks %s \
2+
// RUN: -analyzer-checker=debug.DumpLiveStmts \
3+
// RUN: 2>&1 | FileCheck %s
4+
5+
@interface Item
6+
// ...
7+
@end
8+
9+
@interface Collection
10+
// ...
11+
@end
12+
13+
typedef void (^Blk)();
14+
15+
struct RAII {
16+
Blk blk;
17+
18+
public:
19+
RAII(Blk blk): blk(blk) {}
20+
21+
// CHECK: [ B0 (live statements at block exit) ]
22+
// CHECK-EMPTY:
23+
// CHECK-EMPTY:
24+
// CHECK-NEXT: [ B1 (live statements at block exit) ]
25+
// CHECK-EMPTY:
26+
// CHECK-EMPTY:
27+
// CHECK-NEXT: [ B2 (live statements at block exit) ]
28+
// CHECK-EMPTY:
29+
// CHECK-EMPTY:
30+
31+
~RAII() { blk(); }
32+
33+
// CHECK-NEXT: [ B0 (live statements at block exit) ]
34+
// CHECK-EMPTY:
35+
// CHECK-EMPTY:
36+
// CHECK-NEXT: [ B1 (live statements at block exit) ]
37+
// CHECK-EMPTY:
38+
// CHECK-EMPTY:
39+
// CHECK-NEXT: [ B2 (live statements at block exit) ]
40+
// CHECK-EMPTY:
41+
// CHECK-EMPTY:
42+
};
43+
44+
void foo(Collection *coll) {
45+
RAII raii(^{});
46+
for (Item *item in coll) {}
47+
}
48+
// CHECK-NEXT: [ B0 (live statements at block exit) ]
49+
// CHECK-EMPTY:
50+
// CHECK-EMPTY:
51+
// CHECK-NEXT: [ B1 (live statements at block exit) ]
52+
// CHECK-EMPTY:
53+
// CHECK-EMPTY:
54+
// CHECK-NEXT: [ B2 (live statements at block exit) ]
55+
// CHECK-EMPTY:
56+
// CHECK-NEXT: DeclStmt {{.*}}
57+
// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *'
58+
// CHECK-EMPTY:
59+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue>
60+
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
61+
// CHECK-EMPTY:
62+
// CHECK-NEXT: CompoundStmt {{.*}}
63+
// CHECK-EMPTY:
64+
// CHECK-EMPTY:
65+
// CHECK-NEXT: [ B3 (live statements at block exit) ]
66+
// CHECK-EMPTY:
67+
// CHECK-NEXT: DeclStmt {{.*}}
68+
// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *'
69+
// CHECK-EMPTY:
70+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue>
71+
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
72+
// CHECK-EMPTY:
73+
// CHECK-NEXT: CompoundStmt {{.*}}
74+
// CHECK-EMPTY:
75+
// CHECK-EMPTY:
76+
// CHECK-NEXT: [ B4 (live statements at block exit) ]
77+
// CHECK-EMPTY:
78+
// CHECK-NEXT: DeclStmt {{.*}}
79+
// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *'
80+
// CHECK-EMPTY:
81+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue>
82+
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
83+
// CHECK-EMPTY:
84+
// CHECK-NEXT: CompoundStmt {{.*}}
85+
// CHECK-EMPTY:
86+
// CHECK-EMPTY:
87+
// CHECK-NEXT: [ B5 (live statements at block exit) ]
88+
// CHECK-EMPTY:
89+
// CHECK-NEXT: DeclStmt {{.*}}
90+
// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *'
91+
// CHECK-EMPTY:
92+
// CHECK-NEXT: CompoundStmt {{.*}}
93+
// CHECK-EMPTY:
94+
// CHECK-EMPTY:
95+
// CHECK-NEXT: [ B0 (live statements at block exit) ]
96+
// CHECK-EMPTY:
97+
// CHECK-EMPTY:
98+
// CHECK-NEXT: [ B1 (live statements at block exit) ]
99+
// CHECK-EMPTY:
100+
// CHECK-EMPTY:
101+

0 commit comments

Comments
 (0)