r216076 - [analyzer] IdenticalExpr: don't try to compare integer literals with different widths.
Jordan Rose
jordan_rose at apple.com
Wed Aug 20 09:51:27 PDT 2014
Author: jrose
Date: Wed Aug 20 11:51:26 2014
New Revision: 216076
URL: http://llvm.org/viewvc/llvm-project?rev=216076&view=rev
Log:
[analyzer] IdenticalExpr: don't try to compare integer literals with different widths.
PR20659. Patch by Anders Rönnholm.
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
cfe/trunk/test/Analysis/identical-expressions.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp?rev=216076&r1=216075&r2=216076&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp Wed Aug 20 11:51:26 2014
@@ -445,7 +445,12 @@ static bool isIdenticalStmt(const ASTCon
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);
Modified: cfe/trunk/test/Analysis/identical-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/identical-expressions.cpp?rev=216076&r1=216075&r2=216076&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/identical-expressions.cpp (original)
+++ cfe/trunk/test/Analysis/identical-expressions.cpp Wed Aug 20 11:51:26 2014
@@ -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;
+ }
+}
More information about the cfe-commits
mailing list