[PATCH] D132236: [analyzer] Fix liveness of LazyCompoundVals
Balázs Benics via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 23 08:45:38 PDT 2022
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132236.454861.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220823/c95bfaa7/attachment-0001.bin>
More information about the cfe-commits
mailing list