steakhal updated this revision to Diff 454861. steakhal added a comment. rebase
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132236/new/ https://reviews.llvm.org/D132236 Files: clang/lib/StaticAnalyzer/Core/RegionStore.cpp clang/test/Analysis/trivial-copy-struct.cpp Index: clang/test/Analysis/trivial-copy-struct.cpp =================================================================== --- clang/test/Analysis/trivial-copy-struct.cpp +++ clang/test/Analysis/trivial-copy-struct.cpp @@ -34,3 +34,28 @@ (void)(n1->ptr); (void)(n2->ptr); } + +struct List { + List* next; +}; + +void ptr1(List* n) { + List* n2 = new List(*n); // cctor + if (!n->next) { + if (n2->next) { + clang_analyzer_warnIfReached(); // unreachable + } + } + delete n2; +} + +void ptr2(List* n) { + List* n2 = new List(); // ctor + *n2 = *n; // assignment + if (!n->next) { + if (n2->next) { + clang_analyzer_warnIfReached(); // unreachable + } + } + delete n2; +} Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -2829,22 +2829,14 @@ } void RemoveDeadBindingsWorker::VisitBinding(SVal V) { - // Is it a LazyCompoundVal? All referenced regions are live as well. - if (Optional<nonloc::LazyCompoundVal> LCS = - V.getAs<nonloc::LazyCompoundVal>()) { - - const RegionStoreManager::SValListTy &Vals = RM.getInterestingValues(*LCS); - - for (RegionStoreManager::SValListTy::const_iterator I = Vals.begin(), - E = Vals.end(); - I != E; ++I) - VisitBinding(*I); + const MemRegion *R = V.getAsRegion(); - return; - } + // Is it a LazyCompoundVal? All referenced regions are live as well. + if (auto LCS = V.getAs<nonloc::LazyCompoundVal>()) + R = LCS->getRegion(); // If V is a region, then add it to the worklist. - if (const MemRegion *R = V.getAsRegion()) { + if (R) { AddToWorkList(R); SymReaper.markLive(R);
Index: clang/test/Analysis/trivial-copy-struct.cpp =================================================================== --- clang/test/Analysis/trivial-copy-struct.cpp +++ clang/test/Analysis/trivial-copy-struct.cpp @@ -34,3 +34,28 @@ (void)(n1->ptr); (void)(n2->ptr); } + +struct List { + List* next; +}; + +void ptr1(List* n) { + List* n2 = new List(*n); // cctor + if (!n->next) { + if (n2->next) { + clang_analyzer_warnIfReached(); // unreachable + } + } + delete n2; +} + +void ptr2(List* n) { + List* n2 = new List(); // ctor + *n2 = *n; // assignment + if (!n->next) { + if (n2->next) { + clang_analyzer_warnIfReached(); // unreachable + } + } + delete n2; +} Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -2829,22 +2829,14 @@ } void RemoveDeadBindingsWorker::VisitBinding(SVal V) { - // Is it a LazyCompoundVal? All referenced regions are live as well. - if (Optional<nonloc::LazyCompoundVal> LCS = - V.getAs<nonloc::LazyCompoundVal>()) { - - const RegionStoreManager::SValListTy &Vals = RM.getInterestingValues(*LCS); - - for (RegionStoreManager::SValListTy::const_iterator I = Vals.begin(), - E = Vals.end(); - I != E; ++I) - VisitBinding(*I); + const MemRegion *R = V.getAsRegion(); - return; - } + // Is it a LazyCompoundVal? All referenced regions are live as well. + if (auto LCS = V.getAs<nonloc::LazyCompoundVal>()) + R = LCS->getRegion(); // If V is a region, then add it to the worklist. - if (const MemRegion *R = V.getAsRegion()) { + if (R) { AddToWorkList(R); SymReaper.markLive(R);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits