The ast-dump looks like below. The bug occurs when an assert in the comparison
operator of APInt is triggered between `-IntegerLiteral 0x56924a8 <col:9> 'int'
0 and `-IntegerLiteral 0x56bfba0 <col:9> 'unsigned long' 18446744073709551615
APInt.h:969: bool llvm::APInt::operator==(const llvm::APInt&) const: Assertion
`BitWidth == RHS.BitWidth && "Comparison requires equal bit widths"' failed.
I don't know of a better fix than to check that the bitwidths are equal.
| | `-BinaryOperator 0x56924e0 <line:7:5, col:9> 'long' '='
| | |-DeclRefExpr 0x5692480 <col:5> 'long' lvalue Var 0x5692220 'c' 'long'
| | `-ImplicitCastExpr 0x56924c8 <col:9> 'long' <IntegralCast>
| | `-IntegerLiteral 0x56924a8 <col:9> 'int' 0
| `-CompoundStmt 0x56bfc00 <line:8:10, line:11:3>
| |-CompoundAssignOperator 0x56bfb40 <line:9:5, col:10> 'int' '-='
ComputeLHSTy='int' ComputeResultTy='int'
| | |-DeclRefExpr 0x5692530 <col:5> 'int' lvalue Var 0x56921a0 'b' 'int'
| | `-ImplicitCastExpr 0x56bfb28 <col:10> 'int' <LValueToRValue>
| | `-DeclRefExpr 0x56bfb00 <col:10> 'int' lvalue Var 0x5692130 'a'
'int'
| `-BinaryOperator 0x56bfbd8 <line:10:5, col:9> 'long' '='
| |-DeclRefExpr 0x56bfb78 <col:5> 'long' lvalue Var 0x5692220 'c' 'long'
| `-ImplicitCastExpr 0x56bfbc0 <col:9> 'long' <IntegralCast>
| `-IntegerLiteral 0x56bfba0 <col:9> 'unsigned long'
18446744073709551615
//Anders
________________________________________
Från: Jordan Rose [[email protected]]
Skickat: den 18 augusti 2014 18:36
Till: Anders Rönnholm
Cc: [email protected]
Ämne: Re: [PATCH] fix bug 20659 ICE in alpha.core.IdenticalExpr
Thanks for getting to this so quickly. However, I kind of thought C doesn't
ever allow this—any comparisons between two values should always have already
implicitly converted one type to the other. Is this because we're looking
through casts?
If you're sure this is the right fix (and not, say, somewhere else in the
analyzer), please add a reduced test case as well.
Jordan
On Aug 18, 2014, at 1:18 , Anders Rönnholm <[email protected]> wrote:
> Hi,
>
> Fix for reported bug 20659 in identicalexpression.
>
> //Anders
> <bug-20659.diff>_______________________________________________
> cfe-commits mailing list
> [email protected]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
Index: lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp (revision 215696)
+++ lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp (working copy)
@@ -445,7 +445,12 @@
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: test/Analysis/identical-expressions.cpp
===================================================================
--- test/Analysis/identical-expressions.cpp (revision 215696)
+++ test/Analysis/identical-expressions.cpp (working copy)
@@ -1511,3 +1511,19 @@
else if (x++) // no-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;
+ }
+}
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits