diff options
| author | Chandler Carruth <chandlerc@gmail.com> | 2017-02-28 08:04:20 +0000 |
|---|---|---|
| committer | Chandler Carruth <chandlerc@gmail.com> | 2017-02-28 08:04:20 +0000 |
| commit | d1c95b67bac1cdd7658d25e7d5f07166328bf04c (patch) | |
| tree | e7d0e1a9e88c5526d29487c73e6b95c2d30401bb /llvm/unittests/IR/InstructionsTest.cpp | |
| parent | c986f8765ae81b4aacb3e869b338f0c47e694213 (diff) | |
| download | bcm5719-llvm-d1c95b67bac1cdd7658d25e7d5f07166328bf04c.tar.gz bcm5719-llvm-d1c95b67bac1cdd7658d25e7d5f07166328bf04c.zip | |
[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.
llvm-svn: 296444
Diffstat (limited to 'llvm/unittests/IR/InstructionsTest.cpp')
| -rw-r--r-- | llvm/unittests/IR/InstructionsTest.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index dd599ed74ce..82862601f9b 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/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 |

