diff options
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp | 7 | ||||
-rw-r--r-- | clang/test/Analysis/identical-expressions.cpp | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp index ecb82c9031c..58d0783f397 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp +++ b/clang/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<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); diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp index 3c8040aed8b..1711d8043c1 100644 --- a/clang/test/Analysis/identical-expressions.cpp +++ b/clang/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; + } +} |