]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't crash on printing ConcreteInt of size >64 bits
authorAleksei Sidorin <a.sidorin@samsung.com>
Mon, 23 Apr 2018 15:41:44 +0000 (15:41 +0000)
committerAleksei Sidorin <a.sidorin@samsung.com>
Mon, 23 Apr 2018 15:41:44 +0000 (15:41 +0000)
Printing of ConcreteInts with size >64 bits resulted in assertion failure
in get[Z|S]ExtValue() because these methods are only allowed to be used
with integers of 64 max bit width. This patch fixes the issue.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330605 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/SVals.cpp
test/Analysis/sval-dump-int128.c [new file with mode: 0644]

index a75376543ef73ff206bdfc840c9ba782716b9f2e..2105bcc6fc8108f36ecff258d86b1ac2e1165fcb 100644 (file)
@@ -300,13 +300,9 @@ void SVal::dumpToStream(raw_ostream &os) const {
 void NonLoc::dumpToStream(raw_ostream &os) const {
   switch (getSubKind()) {
     case nonloc::ConcreteIntKind: {
-      const nonloc::ConcreteInt& C = castAs<nonloc::ConcreteInt>();
-      if (C.getValue().isUnsigned())
-        os << C.getValue().getZExtValue();
-      else
-        os << C.getValue().getSExtValue();
-      os << ' ' << (C.getValue().isUnsigned() ? 'U' : 'S')
-         << C.getValue().getBitWidth() << 'b';
+      const auto &Value = castAs<nonloc::ConcreteInt>().getValue();
+      os << Value << ' ' << (Value.isSigned() ? 'S' : 'U')
+         << Value.getBitWidth() << 'b';
       break;
     }
     case nonloc::SymbolValKind:
diff --git a/test/Analysis/sval-dump-int128.c b/test/Analysis/sval-dump-int128.c
new file mode 100644 (file)
index 0000000..a290776
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection %s -verify
+
+void clang_analyzer_dump(unsigned __int128 x);
+
+void testDumpInt128() {
+  clang_analyzer_dump((unsigned __int128)5 << 64); // expected-warning{{92233720368547758080 U128b}}
+}