From: Gabor Horvath Date: Thu, 19 Oct 2017 11:58:21 +0000 (+0000) Subject: [analyzer] Dump signed integers in SymIntExpr and IntSymExpr correctly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c5f57098d7b25b05f8b2d3d0036c7f1ba650dc9;p=clang [analyzer] Dump signed integers in SymIntExpr and IntSymExpr correctly Patch by: Adam Balogh! Differential Revision: https://reviews.llvm.org/D39048 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/SymbolManager.cpp b/lib/StaticAnalyzer/Core/SymbolManager.cpp index 4be85661b6..f2d5ee83f3 100644 --- a/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -31,14 +31,20 @@ void SymIntExpr::dumpToStream(raw_ostream &os) const { os << '('; getLHS()->dumpToStream(os); os << ") " - << BinaryOperator::getOpcodeStr(getOpcode()) << ' ' - << getRHS().getZExtValue(); + << BinaryOperator::getOpcodeStr(getOpcode()) << ' '; + if (getRHS().isUnsigned()) + os << getRHS().getZExtValue(); + else + os << getRHS().getSExtValue(); if (getRHS().isUnsigned()) os << 'U'; } void IntSymExpr::dumpToStream(raw_ostream &os) const { - os << getLHS().getZExtValue(); + if (getLHS().isUnsigned()) + os << getLHS().getZExtValue(); + else + os << getLHS().getSExtValue(); if (getLHS().isUnsigned()) os << 'U'; os << ' ' diff --git a/test/Analysis/expr-inspection.c b/test/Analysis/expr-inspection.c index 59406cd420..ec0e682b65 100644 --- a/test/Analysis/expr-inspection.c +++ b/test/Analysis/expr-inspection.c @@ -8,6 +8,7 @@ void clang_analyzer_numTimesReached(); void foo(int x) { clang_analyzer_dump(x); // expected-warning{{reg_$0}} + clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0) + -1}} int y = 1; clang_analyzer_printState(); for (; y < 3; ++y)