Skip to content

Commit ad576ca

Browse files
committed
[Clang] Do not use the GEP result to infer offset
1 parent b8a4520 commit ad576ca

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

clang/lib/CodeGen/CGBuilder.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ class CGBuilderTy : public CGBuilderBaseTy {
7575
llvm::APInt Offset(
7676
DL.getIndexSizeInBits(Addr.getType()->getPointerAddressSpace()), 0,
7777
/*isSigned=*/true);
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-
}
78+
if (!llvm::GEPOperator::accumulateConstantOffset(
79+
Addr.getElementType(), {getInt32(Idx0), getInt32(Idx1)}, DL,
80+
Offset))
81+
llvm_unreachable(
82+
"accumulateConstantOffset with constant indices should not fail.");
83+
llvm::Type *ElementTy = llvm::GetElementPtrInst::getIndexedType(
84+
Addr.getElementType(), {Idx0, Idx1});
8785
return Address(V, ElementTy,
8886
Addr.getAlignment().alignmentAtOffset(
8987
CharUnits::fromQuantity(Offset.getSExtValue())),

0 commit comments

Comments
 (0)