aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-10-21 12:42:47 +0200
committerNikita Popov <npopov@redhat.com>2024-10-21 12:47:02 +0200
commita18dd29077c84fc076a4ed431d9e815a3d0b6f24 (patch)
tree9a9cb53cbe7ce33ffbd8312bfc6889acbafa6e4c /llvm/lib/Analysis/ConstantFolding.cpp
parentd906ac52ab8ee46090a6696f4ffb34c40ee6abb7 (diff)
downloadllvm-a18dd29077c84fc076a4ed431d9e815a3d0b6f24.zip
llvm-a18dd29077c84fc076a4ed431d9e815a3d0b6f24.tar.gz
llvm-a18dd29077c84fc076a4ed431d9e815a3d0b6f24.tar.bz2
[ConstantFolding] Set signed/implicitTrunc when handling GEP offsets
GEP offsets have sext_or_trunc semantics. We were already doing this for the outer-most GEP, but not for the inner ones. I believe one of the sanitizer buildbot failures was due to this, but I did not manage to reproduce the issue or come up with a test case. Usually the problematic case will already be folded away due to index type canonicalization.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c0104d2..530e928 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -924,7 +924,8 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
Ptr = cast<Constant>(GEP->getOperand(0));
SrcElemTy = GEP->getSourceElementType();
Offset = Offset.sadd_ov(
- APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps)),
+ APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps),
+ /*isSigned=*/true, /*implicitTrunc=*/true),
Overflow);
}