llvm.org GIT mirror llvm / 8db4ddb
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216023 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 6 years ago
2 changed file(s) with 29 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
10351035 static Constant *getGetElementPtr(Constant *C, ArrayRef IdxList,
10361036 bool InBounds = false,
10371037 Type *OnlyIfReducedTy = nullptr) {
1038 return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(),
1039 IdxList.size()),
1040 InBounds);
1038 return getGetElementPtr(
1039 C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()),
1040 InBounds, OnlyIfReducedTy);
10411041 }
10421042 static Constant *getGetElementPtr(Constant *C, Constant *Idx,
10431043 bool InBounds = false,
10451045 // This form of the function only exists to avoid ambiguous overload
10461046 // warnings about whether to convert Idx to ArrayRef or
10471047 // ArrayRef.
1048 return getGetElementPtr(C, cast(Idx), InBounds);
1048 return getGetElementPtr(C, cast(Idx), InBounds, OnlyIfReducedTy);
10491049 }
10501050 static Constant *getGetElementPtr(Constant *C, ArrayRef IdxList,
10511051 bool InBounds = false,
321321 ASSERT_EQ(Int2, Ref->getInitializer());
322322 }
323323
324 TEST(ConstantsTest, GEPReplaceWithConstant) {
325 LLVMContext Context;
326 std::unique_ptr M(new Module("MyModule", Context));
327
328 Type *IntTy = Type::getInt32Ty(Context);
329 Type *PtrTy = PointerType::get(IntTy, 0);
330 auto *C1 = ConstantInt::get(IntTy, 1);
331 auto *Placeholder = new GlobalVariable(
332 *M, IntTy, false, GlobalValue::ExternalWeakLinkage, nullptr);
333 auto *GEP = ConstantExpr::getGetElementPtr(Placeholder, C1);
334 ASSERT_EQ(GEP->getOperand(0), Placeholder);
335
336 auto *Ref =
337 new GlobalVariable(*M, PtrTy, false, GlobalValue::ExternalLinkage, GEP);
338 ASSERT_EQ(GEP, Ref->getInitializer());
339
340 auto *Global = new GlobalVariable(*M, PtrTy, false,
341 GlobalValue::ExternalLinkage, nullptr);
342 auto *Alias = GlobalAlias::create(IntTy, 0, GlobalValue::ExternalLinkage,
343 "alias", Global, M.get());
344 Placeholder->replaceAllUsesWith(Alias);
345 ASSERT_EQ(GEP, Ref->getInitializer());
346 ASSERT_EQ(GEP->getOperand(0), Alias);
347 }
348
324349 } // end anonymous namespace
325350 } // end namespace llvm