mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 22:24:07 +00:00
Fix assert with GEP ptr vector indexing structs
Also fix it calculating the wrong value. The struct index is not a ConstantInt, so it was being interpreted as an array index. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188713 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -203,12 +203,17 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &TD, User *GEP,
|
||||
++i, ++GTI) {
|
||||
Value *Op = *i;
|
||||
uint64_t Size = TD.getTypeAllocSize(GTI.getIndexedType()) & PtrSizeMask;
|
||||
if (ConstantInt *OpC = dyn_cast<ConstantInt>(Op)) {
|
||||
if (OpC->isZero()) continue;
|
||||
if (Constant *OpC = dyn_cast<Constant>(Op)) {
|
||||
if (OpC->isZeroValue())
|
||||
continue;
|
||||
|
||||
// Handle a struct index, which adds its field offset to the pointer.
|
||||
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
|
||||
Size = TD.getStructLayout(STy)->getElementOffset(OpC->getZExtValue());
|
||||
if (OpC->getType()->isVectorTy())
|
||||
OpC = OpC->getSplatValue();
|
||||
|
||||
uint64_t OpValue = cast<ConstantInt>(OpC)->getZExtValue();
|
||||
Size = TD.getStructLayout(STy)->getElementOffset(OpValue);
|
||||
|
||||
if (Size)
|
||||
Result = Builder->CreateAdd(Result, ConstantInt::get(IntPtrTy, Size),
|
||||
|
Reference in New Issue
Block a user