Author: Kirstóf Umann Date: 2020-07-24T21:33:18+02:00 New Revision: 032b78a0762bee129f33e4255ada6d374aa70c71
URL: https://github.com/llvm/llvm-project/commit/032b78a0762bee129f33e4255ada6d374aa70c71 DIFF: https://github.com/llvm/llvm-project/commit/032b78a0762bee129f33e4255ada6d374aa70c71.diff LOG: [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. Added: clang/test/Analysis/live-stmts.mm Modified: clang/lib/StaticAnalyzer/Core/Environment.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Core/Environment.cpp b/clang/lib/StaticAnalyzer/Core/Environment.cpp index 9e6d79bb7dcc..1ccf4c6104a6 100644 --- a/clang/lib/StaticAnalyzer/Core/Environment.cpp +++ b/clang/lib/StaticAnalyzer/Core/Environment.cpp @@ -183,18 +183,12 @@ EnvironmentManager::removeDeadBindings(Environment Env, F.getTreeFactory()); // Iterate over the block-expr bindings. - for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) { + for (Environment::iterator I = Env.begin(), E = Env.end(); + I != E; ++I) { const EnvironmentEntry &BlkExpr = I.getKey(); const SVal &X = I.getData(); - const bool IsBlkExprLive = - SymReaper.isLive(BlkExpr.getStmt(), BlkExpr.getLocationContext()); - - assert((isa<Expr>(BlkExpr.getStmt()) || !IsBlkExprLive) && - "Only Exprs can be live, LivenessAnalysis argues about the liveness " - "of *values*!"); - - if (IsBlkExprLive) { + if (SymReaper.isLive(BlkExpr.getStmt(), BlkExpr.getLocationContext())) { // Copy the binding to the new map. EBMapRef = EBMapRef.add(BlkExpr, X); diff --git a/clang/test/Analysis/live-stmts.mm b/clang/test/Analysis/live-stmts.mm new file mode 100644 index 000000000000..a6ddd03ca5d8 --- /dev/null +++ b/clang/test/Analysis/live-stmts.mm @@ -0,0 +1,101 @@ +// RUN: %clang_analyze_cc1 -w -fblocks %s \ +// RUN: -analyzer-checker=debug.DumpLiveStmts \ +// RUN: 2>&1 | FileCheck %s + +@interface Item +// ... +@end + +@interface Collection +// ... +@end + +typedef void (^Blk)(); + +struct RAII { + Blk blk; + +public: + RAII(Blk blk): blk(blk) {} + +// CHECK: [ B0 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B1 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B2 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: + + ~RAII() { blk(); } + +// CHECK-NEXT: [ B0 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B1 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B2 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +}; + +void foo(Collection *coll) { + RAII raii(^{}); + for (Item *item in coll) {} +} +// CHECK-NEXT: [ B0 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B1 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B2 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *' +// CHECK-EMPTY: +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue> +// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *' +// CHECK-EMPTY: +// CHECK-NEXT: CompoundStmt {{.*}} +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B3 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *' +// CHECK-EMPTY: +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue> +// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *' +// CHECK-EMPTY: +// CHECK-NEXT: CompoundStmt {{.*}} +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B4 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *' +// CHECK-EMPTY: +// CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' <LValueToRValue> +// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *' +// CHECK-EMPTY: +// CHECK-NEXT: CompoundStmt {{.*}} +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B5 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-NEXT: DeclStmt {{.*}} +// CHECK-NEXT: `-VarDecl {{.*}} item 'Item *' +// CHECK-EMPTY: +// CHECK-NEXT: CompoundStmt {{.*}} +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B0 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: +// CHECK-NEXT: [ B1 (live statements at block exit) ] +// CHECK-EMPTY: +// CHECK-EMPTY: + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits