r372454 - Fix bad APInt compare.
Richard Trieu via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 21:18:55 PDT 2019
Author: rtrieu
Date: Fri Sep 20 21:18:54 2019
New Revision: 372454
URL: http://llvm.org/viewvc/llvm-project?rev=372454&view=rev
Log:
Fix bad APInt compare.
APInt comparison require both to have the same bitwidth. Since only the value
is needed, use the compare function APInt::isSameValue instead.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/self-comparison.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=372454&r1=372453&r2=372454&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Sep 20 21:18:54 2019
@@ -3983,7 +3983,8 @@ bool Expr::isSameComparisonOperand(const
const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1);
const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2);
if (Integer1 && Integer2) {
- if (Integer1->getValue() != Integer2->getValue())
+ if (!llvm::APInt::isSameValue(Integer1->getValue(),
+ Integer2->getValue()))
return false;
} else {
if (!isSameComparisonOperand(Idx1, Idx2))
Modified: cfe/trunk/test/SemaCXX/self-comparison.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/self-comparison.cpp?rev=372454&r1=372453&r2=372454&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/self-comparison.cpp (original)
+++ cfe/trunk/test/SemaCXX/self-comparison.cpp Fri Sep 20 21:18:54 2019
@@ -86,6 +86,7 @@ int struct_test(S s1, S s2, S *s3, T t)
return s3->field == s3->field; // expected-warning {{self-comparison always evaluates to true}}
return s3->static_field == S::static_field; // expected-warning {{self-comparison always evaluates to true}}
return s1.array[0] == s1.array[0]; // expected-warning {{self-comparison always evaluates to true}}
+ return s1.array[0] == s1.array[0ull]; // expected-warning {{self-comparison always evaluates to true}}
return s1.array[I1] == s1.array[I1]; // expected-warning {{self-comparison always evaluates to true}}
return s1.array[s2.array[0]] == s1.array[s2.array[0]]; // expected-warning {{self-comparison always evaluates to true}}
return s3->array[t.field] == s3->array[t.field]; // expected-warning {{self-comparison always evaluates to true}}
More information about the cfe-commits
mailing list