@@ -64,21 +64,27 @@ class CGBuilderTy : public CGBuilderBaseTy {
64
64
Address createConstGEP2_32 (Address Addr, unsigned Idx0, unsigned Idx1,
65
65
const llvm::Twine &Name) {
66
66
const llvm::DataLayout &DL = BB->getDataLayout ();
67
- llvm::GetElementPtrInst *GEP ;
67
+ llvm::Value *V ;
68
68
if (IsInBounds)
69
- GEP = cast<llvm::GetElementPtrInst>( CreateConstInBoundsGEP2_32 (
70
- Addr. getElementType (), emitRawPointerFromAddress (Addr), Idx0, Idx1 ,
71
- Name) );
69
+ V = CreateConstInBoundsGEP2_32 (Addr. getElementType (),
70
+ emitRawPointerFromAddress (Addr), Idx0,
71
+ Idx1, Name);
72
72
else
73
- GEP = cast<llvm::GetElementPtrInst>(CreateConstGEP2_32 (
74
- Addr.getElementType (), emitRawPointerFromAddress (Addr), Idx0, Idx1,
75
- Name));
73
+ V = CreateConstGEP2_32 (Addr.getElementType (),
74
+ emitRawPointerFromAddress (Addr), Idx0, Idx1, Name);
76
75
llvm::APInt Offset (
77
76
DL.getIndexSizeInBits (Addr.getType ()->getPointerAddressSpace ()), 0 ,
78
77
/* isSigned=*/ true );
79
- if (!GEP->accumulateConstantOffset (DL, Offset))
80
- llvm_unreachable (" offset of GEP with constants is always computable" );
81
- return Address (GEP, GEP->getResultElementType (),
78
+ llvm::Type *ElementTy = nullptr ;
79
+ if (auto *GEP = dyn_cast<llvm::GEPOperator>(V)) {
80
+ if (!GEP->accumulateConstantOffset (DL, Offset))
81
+ llvm_unreachable (" offset of GEP with constants is always computable" );
82
+ ElementTy = GEP->getResultElementType ();
83
+ } else {
84
+ ElementTy = llvm::GetElementPtrInst::getIndexedType (Addr.getElementType (),
85
+ {Idx0, Idx1});
86
+ }
87
+ return Address (V, ElementTy,
82
88
Addr.getAlignment ().alignmentAtOffset (
83
89
CharUnits::fromQuantity (Offset.getSExtValue ())),
84
90
IsInBounds ? Addr.isKnownNonNull () : NotKnownNonNull);
@@ -219,21 +225,17 @@ class CGBuilderTy : public CGBuilderBaseTy {
219
225
// / true.
220
226
using CGBuilderBaseTy::CreateStructGEP;
221
227
Address CreateStructGEP (Address Addr, unsigned Index,
222
- const llvm::Twine &Name = " " ,
223
- bool IsBaseConstantNull = false ) {
228
+ const llvm::Twine &Name = " " ) {
224
229
llvm::StructType *ElTy = cast<llvm::StructType>(Addr.getElementType ());
225
230
const llvm::DataLayout &DL = BB->getDataLayout ();
226
231
const llvm::StructLayout *Layout = DL.getStructLayout (ElTy);
227
232
auto Offset = CharUnits::fromQuantity (Layout->getElementOffset (Index));
228
233
229
- llvm::GEPNoWrapFlags NWFlags = llvm::GEPNoWrapFlags::noUnsignedWrap ();
230
- if (!IsBaseConstantNull)
231
- NWFlags |= llvm::GEPNoWrapFlags::inBounds ();
232
- return Address (
233
- CreateConstGEP2_32 (Addr.getElementType (), Addr.getBasePointer (), 0 ,
234
- Index, Name, NWFlags),
235
- ElTy->getElementType (Index),
236
- Addr.getAlignment ().alignmentAtOffset (Offset), Addr.isKnownNonNull ());
234
+ return Address (CreateStructGEP (Addr.getElementType (), Addr.getBasePointer (),
235
+ Index, Name),
236
+ ElTy->getElementType (Index),
237
+ Addr.getAlignment ().alignmentAtOffset (Offset),
238
+ Addr.isKnownNonNull ());
237
239
}
238
240
239
241
// / Given
0 commit comments