From 8ecdd0ae6f47b0d36f64c37c0890474a76e42cb6 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Wed, 20 Aug 2014 16:51:26 +0000 Subject: [PATCH] [analyzer] IdenticalExpr: don't try to compare integer literals with different widths. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 7 ++++++- test/Analysis/identical-expressions.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp b/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp index ecb82c9031..58d0783f39 100644 --- a/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp @@ -445,7 +445,12 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1, case Stmt::IntegerLiteralClass: { const IntegerLiteral *IntLit1 = cast(Stmt1); const IntegerLiteral *IntLit2 = cast(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(Stmt1); diff --git a/test/Analysis/identical-expressions.cpp b/test/Analysis/identical-expressions.cpp index 3c8040aed8..1711d8043c 100644 --- a/test/Analysis/identical-expressions.cpp +++ b/test/Analysis/identical-expressions.cpp @@ -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; + } +} -- 2.40.0