]> granicus.if.org Git - clang/commitdiff
[analyzer] IdenticalExpr: don't try to compare integer literals with different widths.
authorJordan Rose <jordan_rose@apple.com>
Wed, 20 Aug 2014 16:51:26 +0000 (16:51 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 20 Aug 2014 16:51:26 +0000 (16:51 +0000)
PR20659. Patch by Anders Rönnholm.

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

lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
test/Analysis/identical-expressions.cpp

index ecb82c9031cf5a5e3b8a247f719e88050b909c38..58d0783f3974dd324d0285bbbc56a35d0b0cd330 100644 (file)
@@ -445,7 +445,12 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
   case Stmt::IntegerLiteralClass: {
     const IntegerLiteral *IntLit1 = cast<IntegerLiteral>(Stmt1);
     const IntegerLiteral *IntLit2 = cast<IntegerLiteral>(Stmt2);
-    return IntLit1->getValue() == IntLit2->getValue();
+
+    llvm::APInt I1 = IntLit1->getValue();
+    llvm::APInt I2 = IntLit2->getValue();
+    if (I1.getBitWidth() != I2.getBitWidth())
+      return false;
+    return  I1 == I2;
   }
   case Stmt::FloatingLiteralClass: {
     const FloatingLiteral *FloatLit1 = cast<FloatingLiteral>(Stmt1);
index 3c8040aed8b2b1c3d0d6cd9adf37a371a0cbccdc..1711d8043c1f000467b34909daaf77e70eecff63 100644 (file)
@@ -1518,3 +1518,15 @@ void test_warn_wchar() {
 void test_nowarn_wchar() {
   const wchar_t * a = 0 ? L"No" : L"Warning";
 }
+
+void test_nowarn_long() {
+  int a =0, b = 0;
+  long c;
+  if (0) {
+    b -= a;
+    c = 0;
+  } else { // no-warning
+    b -= a;
+    c = 0xFFFFFFFFFFFFFFFF;
+  }
+}