[PATCH] D66131: [analyzer] Don't track the condition of foreach loops
Kristóf Umann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 19:43:24 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369613: [analyzer] Don't track the condition of foreach loops (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D66131?vs=214791&id=216540#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66131/new/
https://reviews.llvm.org/D66131
Files:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
Index: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
===================================================================
--- cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
+++ cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
@@ -407,6 +407,39 @@
}
} // end of namespace condition_written_in_nested_stackframe_before_assignment
+namespace dont_explain_foreach_loops {
+
+struct Iterator {
+ int *pos;
+ bool operator!=(Iterator other) const {
+ return pos && other.pos && pos != other.pos;
+ }
+ int operator*();
+ Iterator operator++();
+};
+
+struct Container {
+ Iterator begin();
+ Iterator end();
+};
+
+void f(Container Cont) {
+ int flag = 0;
+ int *x = 0; // expected-note-re{{{{^}}'x' initialized to a null pointer value{{$}}}}
+ for (int i : Cont)
+ if (i) // expected-note-re {{{{^}}Assuming 'i' is not equal to 0{{$}}}}
+ // expected-note-re at -1{{{{^}}Taking true branch{{$}}}}
+ // debug-note-re at -2{{{{^}}Tracking condition 'i'{{$}}}}
+ flag = i;
+
+ if (flag) // expected-note-re{{{{^}}'flag' is not equal to 0{{$}}}}
+ // expected-note-re at -1{{{{^}}Taking true branch{{$}}}}
+ // debug-note-re at -2{{{{^}}Tracking condition 'flag'{{$}}}}
+ *x = 5; // expected-warning{{Dereference of null pointer}}
+ // expected-note at -1{{Dereference of null pointer}}
+}
+} // end of namespace dont_explain_foreach_loops
+
namespace condition_lambda_capture_by_reference_last_write {
int getInt();
Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1800,6 +1800,11 @@
return nullptr;
if (ControlDeps.isControlDependent(OriginB, NB)) {
+ // We don't really want to explain for range loops. Evidence suggests that
+ // the only thing that leads to is the addition of calls to operator!=.
+ if (isa<CXXForRangeStmt>(NB->getTerminator()))
+ return nullptr;
+
if (const Expr *Condition = NB->getLastCondition()) {
// Keeping track of the already tracked conditions on a visitor level
// isn't sufficient, because a new visitor is created for each tracked
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66131.216540.patch
Type: text/x-patch
Size: 2335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190822/e2659945/attachment.bin>
More information about the cfe-commits
mailing list