Skip to content

Commit

Permalink
[analyzer] ConditionBRVisitor: Boolean support
Browse files Browse the repository at this point in the history
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

llvm-svn: 362027
  • Loading branch information
Charusso committed May 29, 2019
1 parent d1f0ec3 commit 2e896b8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
15 changes: 11 additions & 4 deletions clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -829,9 +829,9 @@
</array>
</array>
<key>extended_message</key>
<string>&apos;fail&apos; is 1</string>
<string>&apos;fail&apos; is true</string>
<key>message</key>
<string>&apos;fail&apos; is 1</string>
<string>&apos;fail&apos; is true</string>
</dict>
<dict>
<key>kind</key><string>control</string>
Expand Down
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions clang/test/Analysis/inner-pointer.cpp
Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/use-after-move.cpp
Expand Up @@ -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'}}
Expand Down

0 comments on commit 2e896b8

Please sign in to comment.