From: Csaba Dabis Date: Wed, 29 May 2019 20:34:29 +0000 (+0000) Subject: [analyzer] ConditionBRVisitor: Boolean support X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=476b9144efd6448adb4489ead817454a76b26126;p=clang [analyzer] ConditionBRVisitor: Boolean support Summary: - Reviewers: NoQ, george.karpenkov Reviewed By: NoQ, george.karpenkov Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp Tags: #clang Differential Revision: https://reviews.llvm.org/D58207 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362027 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index c45b519582..db7559b10b 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -2323,10 +2323,17 @@ bool ConditionBRVisitor::printValue(const Expr *CondVarExpr, raw_ostream &Out, if (!IsAssuming) IntValue = getConcreteIntegerValue(CondVarExpr, N); - if (IsAssuming || !IntValue.hasValue()) - Out << (TookTrue ? "not equal to 0" : "0"); - else - Out << *IntValue.getValue(); + if (IsAssuming || !IntValue.hasValue()) { + if (Ty->isBooleanType()) + Out << (TookTrue ? "true" : "false"); + else + Out << (TookTrue ? "not equal to 0" : "0"); + } else { + if (Ty->isBooleanType()) + Out << (IntValue.getValue()->getBoolValue() ? "true" : "false"); + else + Out << *IntValue.getValue(); + } return true; } diff --git a/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist b/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist index 5be7d0adb9..f6bfc87db5 100644 --- a/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist +++ b/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist @@ -829,9 +829,9 @@ extended_message - 'fail' is 1 + 'fail' is true message - 'fail' is 1 + 'fail' is true kindcontrol diff --git a/test/Analysis/diagnostics/no-store-func-path-notes.cpp b/test/Analysis/diagnostics/no-store-func-path-notes.cpp index 39b7dd9e49..c2a3d64801 100644 --- a/test/Analysis/diagnostics/no-store-func-path-notes.cpp +++ b/test/Analysis/diagnostics/no-store-func-path-notes.cpp @@ -102,7 +102,7 @@ struct C { C(int pX, int pY, bool Flag) { x = pX; - if (Flag) // expected-note{{Assuming 'Flag' is not equal to 0}} + if (Flag) // expected-note{{Assuming 'Flag' is true}} // expected-note@-1{{Taking true branch}} return; // expected-note{{Returning without writing to 'this->y'}} y = pY; diff --git a/test/Analysis/inner-pointer.cpp b/test/Analysis/inner-pointer.cpp index 81b750d7e5..f4646c20fc 100644 --- a/test/Analysis/inner-pointer.cpp +++ b/test/Analysis/inner-pointer.cpp @@ -38,9 +38,9 @@ void deref_after_scope_char(bool cond) { std::string s; const char *c2 = s.c_str(); if (cond) { - // expected-note@-1 {{Assuming 'cond' is not equal to 0}} + // expected-note@-1 {{Assuming 'cond' is true}} // expected-note@-2 {{Taking true branch}} - // expected-note@-3 {{Assuming 'cond' is 0}} + // expected-note@-3 {{Assuming 'cond' is false}} // expected-note@-4 {{Taking false branch}} consume(c); // expected-warning {{Inner pointer of container used after re/deallocation}} // expected-note@-1 {{Inner pointer of container used after re/deallocation}} @@ -73,9 +73,9 @@ void deref_after_scope_wchar_t(bool cond) { std::wstring s; const wchar_t *c2 = s.c_str(); if (cond) { - // expected-note@-1 {{Assuming 'cond' is not equal to 0}} + // expected-note@-1 {{Assuming 'cond' is true}} // expected-note@-2 {{Taking true branch}} - // expected-note@-3 {{Assuming 'cond' is 0}} + // expected-note@-3 {{Assuming 'cond' is false}} // expected-note@-4 {{Taking false branch}} consume(c); // expected-warning {{Inner pointer of container used after re/deallocation}} // expected-note@-1 {{Inner pointer of container used after re/deallocation}} @@ -122,9 +122,9 @@ void multiple_symbols(bool cond) { std::string s2; const char *c2 = s2.c_str(); if (cond) { - // expected-note@-1 {{Assuming 'cond' is not equal to 0}} + // expected-note@-1 {{Assuming 'cond' is true}} // expected-note@-2 {{Taking true branch}} - // expected-note@-3 {{Assuming 'cond' is 0}} + // expected-note@-3 {{Assuming 'cond' is false}} // expected-note@-4 {{Taking false branch}} consume(c1); // expected-warning {{Inner pointer of container used after re/deallocation}} // expected-note@-1 {{Inner pointer of container used after re/deallocation}} diff --git a/test/Analysis/use-after-move.cpp b/test/Analysis/use-after-move.cpp index e58301df8b..c25f4393cd 100644 --- a/test/Analysis/use-after-move.cpp +++ b/test/Analysis/use-after-move.cpp @@ -395,7 +395,7 @@ void uniqueTest(bool cond) { A b; b = std::move(a); // peaceful-note {{Object 'a' is moved}} - if (cond) { // peaceful-note {{Assuming 'cond' is not equal to 0}} + if (cond) { // peaceful-note {{Assuming 'cond' is true}} // peaceful-note@-1 {{Taking true branch}} a.foo(); // peaceful-warning {{Method called on moved-from object 'a'}} // peaceful-note@-1 {{Method called on moved-from object 'a'}}