[llvm] bdee805 - [ConstantFold] ConstantFoldGetElementPtr - use APInt::isNegative() instead of getSExtValue() to support big ints
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 24 10:19:02 PDT 2021
Author: Simon Pilgrim
Date: 2021-09-24T18:18:53+01:00
New Revision: bdee805b3277e04677490f42e62aa28478331254
URL: https://github.com/llvm/llvm-project/commit/bdee805b3277e04677490f42e62aa28478331254
DIFF: https://github.com/llvm/llvm-project/commit/bdee805b3277e04677490f42e62aa28478331254.diff
LOG: [ConstantFold] ConstantFoldGetElementPtr - use APInt::isNegative() instead of getSExtValue() to support big ints
Fixes fuzz test: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39197
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/SCCP/apint-bigint2.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index b3b296b9998dc..2c0532bbf3e00 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -2326,7 +2326,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
if (isIndexInRangeOfArrayType(STy->getNumElements(), CI))
// It's in range, skip to the next index.
continue;
- if (CI->getSExtValue() < 0) {
+ if (CI->isNegative()) {
// It's out of range and negative, don't try to factor it.
Unknown = true;
continue;
@@ -2337,7 +2337,7 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
for (unsigned I = 0, E = CV->getNumElements(); I != E; ++I) {
auto *CI = cast<ConstantInt>(CV->getElementAsConstant(I));
InRange &= isIndexInRangeOfArrayType(STy->getNumElements(), CI);
- if (CI->getSExtValue() < 0) {
+ if (CI->isNegative()) {
Unknown = true;
break;
}
diff --git a/llvm/test/Transforms/SCCP/apint-bigint2.ll b/llvm/test/Transforms/SCCP/apint-bigint2.ll
index 0de8f3954cc5f..3639d13268984 100644
--- a/llvm/test/Transforms/SCCP/apint-bigint2.ll
+++ b/llvm/test/Transforms/SCCP/apint-bigint2.ll
@@ -62,3 +62,19 @@ define void @index_too_large() {
store i101* %ptr2, i101** undef
ret void
}
+
+; OSS-Fuzz #39197
+; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39197
+ at 0 = external dso_local unnamed_addr constant [16 x i8]
+define void @ossfuzz_39197() {
+; CHECK-LABEL: @ossfuzz_39197(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret void
+;
+entry:
+ %B5 = or i72 0, 2361183241434822606847
+ %i = add nuw nsw i72 %B5, 0
+ %i1 = lshr i72 %i, 1
+ %i2 = getelementptr inbounds [4 x [4 x i8]], [4 x [4 x i8]]* bitcast ([16 x i8]* @0 to [4 x [4 x i8]]*), i72 0, i72 0, i72 %i1
+ ret void
+}
More information about the llvm-commits
mailing list