[llvm] 462ab98 - [ConstraintElim] Fix signed integer overflow for inbounds GEP.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 16 15:25:48 PDT 2022
Author: Florian Hahn
Date: 2022-10-16T23:25:28+01:00
New Revision: 462ab9810dd1774970e44264c35e8aec35e7460a
URL: https://github.com/llvm/llvm-project/commit/462ab9810dd1774970e44264c35e8aec35e7460a
DIFF: https://github.com/llvm/llvm-project/commit/462ab9810dd1774970e44264c35e8aec35e7460a.diff
LOG: [ConstraintElim] Fix signed integer overflow for inbounds GEP.
For inbounds GEPs, signed overflow yields poison, so it is fine for the
coefficients to wrap as well. This fixes an UBSan failure.
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 1be235898be7..c208eb36449c 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -270,7 +270,7 @@ decomposeGEP(GetElementPtrInst &GEP,
Result.emplace_back(Scale, Index);
} else {
for (auto &KV : IdxResult)
- KV.Coefficient *= Scale;
+ KV.Coefficient = multiplyWithOverflow(KV.Coefficient, Scale);
Result[0].Coefficient += IdxResult[0].Coefficient;
append_range(Result, ArrayRef<DecompEntry>(IdxResult).drop_front());
}
More information about the llvm-commits
mailing list