aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/InstructionsTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-12-04 17:14:48 +0100
committerNikita Popov <npopov@redhat.com>2024-12-04 17:17:58 +0100
commitb79007d8a6fed51ec2e06aeaec31968122cfcd09 (patch)
treee1ab5eb8275bd578816b65d9e64d97aae6c29172 /llvm/unittests/IR/InstructionsTest.cpp
parentba43a102a929eb8aae60580e14f3192a705e1805 (diff)
downloadllvm-b79007d8a6fed51ec2e06aeaec31968122cfcd09.zip
llvm-b79007d8a6fed51ec2e06aeaec31968122cfcd09.tar.gz
llvm-b79007d8a6fed51ec2e06aeaec31968122cfcd09.tar.bz2
[IR] Fix accumulateConstantOffset() on zero-index GEP
These are degenerate but not malformed, so make sure we don't crash.
Diffstat (limited to 'llvm/unittests/IR/InstructionsTest.cpp')
-rw-r--r--llvm/unittests/IR/InstructionsTest.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp
index b4dbc4e..a46f3ca 100644
--- a/llvm/unittests/IR/InstructionsTest.cpp
+++ b/llvm/unittests/IR/InstructionsTest.cpp
@@ -898,6 +898,20 @@ TEST(InstructionsTest, GEPIndices) {
delete GEPI;
}
+TEST(InstructionsTest, ZeroIndexGEP) {
+ LLVMContext Context;
+ DataLayout DL;
+ Type *PtrTy = PointerType::getUnqual(Context);
+ auto *GEP = GetElementPtrInst::Create(Type::getInt8Ty(Context),
+ PoisonValue::get(PtrTy), {});
+
+ APInt Offset(DL.getIndexTypeSizeInBits(PtrTy), 0);
+ EXPECT_TRUE(GEP->accumulateConstantOffset(DL, Offset));
+ EXPECT_TRUE(Offset.isZero());
+
+ delete GEP;
+}
+
TEST(InstructionsTest, SwitchInst) {
LLVMContext C;