]> granicus.if.org Git - clang/commitdiff
[analyzer] Dump signed integers in SymIntExpr and IntSymExpr correctly
authorGabor Horvath <xazax.hun@gmail.com>
Thu, 19 Oct 2017 11:58:21 +0000 (11:58 +0000)
committerGabor Horvath <xazax.hun@gmail.com>
Thu, 19 Oct 2017 11:58:21 +0000 (11:58 +0000)
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

lib/StaticAnalyzer/Core/SymbolManager.cpp
test/Analysis/expr-inspection.c

index 4be85661b645f12bc44e2eba82b9a149cc121621..f2d5ee83f3cc77fc0b7d4c23ce326806ef5ba44b 100644 (file)
@@ -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 << ' '
index 59406cd420adfdb5ff55dbac622f91e674bdff20..ec0e682b65360377c8c4b0cad28b96f1e3816cf0 100644 (file)
@@ -8,6 +8,7 @@ void clang_analyzer_numTimesReached();
 
 void foo(int x) {
   clang_analyzer_dump(x); // expected-warning{{reg_$0<int x>}}
+  clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0<int x>) + -1}}
   int y = 1;
   clang_analyzer_printState();
   for (; y < 3; ++y)