From 4d764c760bc19a720a89edadb05d5c13fc5908b6 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Sat, 21 Sep 2019 04:18:54 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372454 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 3 ++- test/SemaCXX/self-comparison.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index b5fb7fafb0..c9394bba2d 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -3983,7 +3983,8 @@ bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) { const auto Integer1 = dyn_cast(Idx1); const auto Integer2 = dyn_cast(Idx2); if (Integer1 && Integer2) { - if (Integer1->getValue() != Integer2->getValue()) + if (!llvm::APInt::isSameValue(Integer1->getValue(), + Integer2->getValue())) return false; } else { if (!isSameComparisonOperand(Idx1, Idx2)) diff --git a/test/SemaCXX/self-comparison.cpp b/test/SemaCXX/self-comparison.cpp index 4ea16665f1..e20706a8b6 100644 --- a/test/SemaCXX/self-comparison.cpp +++ b/test/SemaCXX/self-comparison.cpp @@ -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}} -- cgit v1.2.1