summaryrefslogtreecommitdiff
path: root/unittests/IR
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2017-02-28 08:04:20 +0000
committerChandler Carruth <chandlerc@gmail.com>2017-02-28 08:04:20 +0000
commitbff5a6eea5e1b09527df09327d0275acfbc65cad (patch)
treeeb7e5ea966526242ccaeb900c5c15afe272afcc5 /unittests/IR
parent925071a16e0424c60e3599218544358b356d25f1 (diff)
downloadllvm-bff5a6eea5e1b09527df09327d0275acfbc65cad.tar.gz
[IR] Add range accessors for the indices of a GEP instruction.
These were noticed as missing in a code review. Add them and the boring unit test to make sure they compile and DTRT. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296444 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/IR')
-rw-r--r--unittests/IR/InstructionsTest.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp
index dd599ed74ce0..82862601f9b1 100644
--- a/unittests/IR/InstructionsTest.cpp
+++ b/unittests/IR/InstructionsTest.cpp
@@ -640,5 +640,40 @@ TEST_F(ModuleWithFunctionTest, DropPoisonGeneratingFlags) {
}
}
+TEST(InstructionsTest, GEPIndices) {
+ LLVMContext Context;
+ IRBuilder<NoFolder> Builder(Context);
+ Type *ElementTy = Builder.getInt8Ty();
+ Type *ArrTy = ArrayType::get(ArrayType::get(ElementTy, 64), 64);
+ Value *Indices[] = {
+ Builder.getInt32(0),
+ Builder.getInt32(13),
+ Builder.getInt32(42) };
+
+ Value *V = Builder.CreateGEP(ArrTy, UndefValue::get(PointerType::getUnqual(ArrTy)),
+ Indices);
+ ASSERT_TRUE(isa<GetElementPtrInst>(V));
+
+ auto *GEPI = cast<GetElementPtrInst>(V);
+ ASSERT_NE(GEPI->idx_begin(), GEPI->idx_end());
+ ASSERT_EQ(GEPI->idx_end(), std::next(GEPI->idx_begin(), 3));
+ EXPECT_EQ(Indices[0], GEPI->idx_begin()[0]);
+ EXPECT_EQ(Indices[1], GEPI->idx_begin()[1]);
+ EXPECT_EQ(Indices[2], GEPI->idx_begin()[2]);
+ EXPECT_EQ(GEPI->idx_begin(), GEPI->indices().begin());
+ EXPECT_EQ(GEPI->idx_end(), GEPI->indices().end());
+
+ const auto *CGEPI = GEPI;
+ ASSERT_NE(CGEPI->idx_begin(), CGEPI->idx_end());
+ ASSERT_EQ(CGEPI->idx_end(), std::next(CGEPI->idx_begin(), 3));
+ EXPECT_EQ(Indices[0], CGEPI->idx_begin()[0]);
+ EXPECT_EQ(Indices[1], CGEPI->idx_begin()[1]);
+ EXPECT_EQ(Indices[2], CGEPI->idx_begin()[2]);
+ EXPECT_EQ(CGEPI->idx_begin(), CGEPI->indices().begin());
+ EXPECT_EQ(CGEPI->idx_end(), CGEPI->indices().end());
+
+ delete GEPI;
+}
+
} // end anonymous namespace
} // end namespace llvm