From 650a4360cda95361d615c6a0160f445ba6c9579a Mon Sep 17 00:00:00 2001 From: Kristof Umann Date: Wed, 14 Aug 2019 13:51:52 +0000 Subject: [PATCH] [analyzer][NFC] Prove that we only track the evaluated part of the condition ...because we're working with a BugReporterVisitor, and the non-evaluated part of the condition isn't in the bugpath. Differential Revision: https://reviews.llvm.org/D65290 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368853 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../track-control-dependency-conditions.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/Analysis/track-control-dependency-conditions.cpp b/test/Analysis/track-control-dependency-conditions.cpp index b914486602..016ba3c5dc 100644 --- a/test/Analysis/track-control-dependency-conditions.cpp +++ b/test/Analysis/track-control-dependency-conditions.cpp @@ -532,6 +532,7 @@ void f(int flag) { } #undef assert + } // end of namespace dont_track_assertlike_and_conditions namespace dont_track_assertlike_or_conditions { @@ -697,3 +698,37 @@ void f(int flag) { #undef assert } // end of namespace dont_track_assert2like_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@-1{{Tracking condition 'x'}} + // expected-note@-2{{Taking false branch}} + return; + + int flag, flag2; + bar(flag); // tracking-note{{Calling 'bar'}} + // tracking-note@-1{{Returning from 'bar'}} + bar2(flag2); + + if (flag && flag2) // expected-note {{Assuming 'flag' is 0}} + // expected-note@-1{{Left side of '&&' is false}} + // debug-note@-2{{Tracking condition 'flag'}} + return; + + *x = 5; // expected-warning{{Dereference of null pointer}} + // expected-note@-1{{Dereference of null pointer}} +} + +} // end of namespace only_track_the_evaluated_condition -- 2.40.0