This fixes another integer overflow that was exposed by a variant of the
test case from #62226.
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/MathExtras.h"
#include <string>
// the constant.
R[0] += 1;
for (auto &C : R)
- C *= -1;
+ if (MulOverflow(C, int64_t(-1), C))
+ return {};
return R;
}
// If there is no solution with the negation of R added to the system, the
// condition must hold based on the existing constraints.
R = ConstraintSystem::negate(R);
+ if (R.empty())
+ return false;
auto NewSystem = *this;
NewSystem.addVariableRow(R);
NumCondsRemoved++;
Changed = true;
}
- if (CSToUse.isConditionImplied(ConstraintSystem::negate(R.Coefficients))) {
+ auto Negated = ConstraintSystem::negate(R.Coefficients);
+ if (!Negated.empty() && CSToUse.isConditionImplied(Negated)) {
if (!DebugCounter::shouldExecute(EliminatedCounter))
return false;
ret i1 %icmp
}
+define i1 @test_overflow_in_negate_constraint(i8 %x, i64 %y) {
+bb:
+ %zext = zext i8 %x to i64
+ %shl = shl nuw nsw i64 %zext, 63
+ %icmp = icmp uge i64 %y, %shl
+ ret i1 %icmp
+}