diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-08-19 21:18:21 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-08-19 21:18:21 +0000 |
commit | 35de5b8ca1e916b58e0eed685287985fc2395af6 (patch) | |
tree | 774289a3db8aee1021c8a9ff3ae8d6cf828d569e /llvm | |
parent | c8eccd1147800b8a2720ded56f42c7342812430e (diff) | |
download | bcm5719-llvm-35de5b8ca1e916b58e0eed685287985fc2395af6.tar.gz bcm5719-llvm-35de5b8ca1e916b58e0eed685287985fc2395af6.zip |
IR: Fix a missed case when threading OnlyIfReduced through ConstantExpr
In r216015 I missed propagating `OnlyIfReduced` through the inline
versions of `getGetElementPtr()` (I was relying on compile failures on
mismatches between the header and source signatures to get them all).
llvm-svn: 216023
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/IR/Constants.h | 8 | ||||
-rw-r--r-- | llvm/unittests/IR/ConstantsTest.cpp | 25 |
2 files changed, 29 insertions, 4 deletions
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index 8591f06c72e..5625b3f5d8e 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -1036,9 +1036,9 @@ public: static Constant *getGetElementPtr(Constant *C, ArrayRef<Constant *> IdxList, bool InBounds = false, Type *OnlyIfReducedTy = nullptr) { - return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(), - IdxList.size()), - InBounds); + return getGetElementPtr( + C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()), + InBounds, OnlyIfReducedTy); } static Constant *getGetElementPtr(Constant *C, Constant *Idx, bool InBounds = false, @@ -1046,7 +1046,7 @@ public: // This form of the function only exists to avoid ambiguous overload // warnings about whether to convert Idx to ArrayRef<Constant *> or // ArrayRef<Value *>. - return getGetElementPtr(C, cast<Value>(Idx), InBounds); + return getGetElementPtr(C, cast<Value>(Idx), InBounds, OnlyIfReducedTy); } static Constant *getGetElementPtr(Constant *C, ArrayRef<Value *> IdxList, bool InBounds = false, diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp index f14b0903548..5414b25ca3a 100644 --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -322,5 +322,30 @@ TEST(ConstantsTest, ConstantExprReplaceWithConstant) { ASSERT_EQ(Int2, Ref->getInitializer()); } +TEST(ConstantsTest, GEPReplaceWithConstant) { + LLVMContext Context; + std::unique_ptr<Module> M(new Module("MyModule", Context)); + + Type *IntTy = Type::getInt32Ty(Context); + Type *PtrTy = PointerType::get(IntTy, 0); + auto *C1 = ConstantInt::get(IntTy, 1); + auto *Placeholder = new GlobalVariable( + *M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr); + auto *GEP = ConstantExpr::getGetElementPtr(Placeholder, C1); + ASSERT_EQ(GEP->getOperand(0), Placeholder); + + auto *Ref = + new GlobalVariable(*M, PtrTy, false, GlobalValue::ExternalLinkage, GEP); + ASSERT_EQ(GEP, Ref->getInitializer()); + + auto *Global = new GlobalVariable(*M, PtrTy, false, + GlobalValue::ExternalLinkage, nullptr); + auto *Alias = GlobalAlias::create(IntTy, 0, GlobalValue::ExternalLinkage, + "alias", Global, M.get()); + Placeholder->replaceAllUsesWith(Alias); + ASSERT_EQ(GEP, Ref->getInitializer()); + ASSERT_EQ(GEP->getOperand(0), Alias); +} + } // end anonymous namespace } // end namespace llvm |