[PATCH] D65290: [analyzer][NFC] Prove that we only track the evaluated part of the condition

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 25 09:22:48 PDT 2019


Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, Charusso, rnkovacs, baloghadamsoftware, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet, whisperity.
Szelethus added a parent revision: D65287: [analyzer][CFG] Don't track the condition of asserts.

...because we're working with a `BugReporterVisitor`, and the non-evaluated part of the condition isn't in the bugpath.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65290

Files:
  clang/test/Analysis/track-control-dependency-conditions.cpp


Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===================================================================
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -502,6 +502,7 @@
 }
 
 #undef assert
+
 } // end of namespace dont_track_assertlike_and_conditions
 
 namespace dont_track_assertlike_or_conditions {
@@ -541,3 +542,37 @@
 
 #undef assert
 } // end of namespace dont_track_assertlike_or_conditions
+
+namespace only_track_the_evaluated_condition {
+
+bool coin();
+
+void bar(int &flag) {
+  flag = coin(); // tracking-note{{Value assigned to 'flag'}}
+}
+
+void bar2(int &flag2) {
+  flag2 = coin();
+}
+
+void f(int *x) {
+  if (x) // expected-note{{Assuming 'x' is null}}
+         // debug-note at -1{{Tracking condition 'x'}}
+         // expected-note at -2{{Taking false branch}}
+    return;
+
+  int flag, flag2;
+  bar(flag); // tracking-note{{Calling 'bar'}}
+             // tracking-note at -1{{Returning from 'bar'}}
+  bar2(flag2);
+
+  if (flag && flag2) // expected-note   {{Assuming 'flag' is 0}}
+                     // expected-note at -1{{Left side of '&&' is false}}
+                     // debug-note at -2{{Tracking condition 'flag'}}
+    return;
+
+  *x = 5; // expected-warning{{Dereference of null pointer}}
+          // expected-note at -1{{Dereference of null pointer}}
+}
+
+} // end of namespace only_track_the_evaluated_condition


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65290.211779.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190725/453650e3/attachment-0001.bin>


More information about the cfe-commits mailing list