1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed vector GEP

This commit is contained in:
Brian Fiete 2021-01-26 17:01:30 -08:00
parent 9ce7a535b4
commit ea34f0c2fd

View file

@ -2303,7 +2303,7 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a
// We assume we never do both an idx0 and idx1 at once. Fix if we change that. // We assume we never do both an idx0 and idx1 at once. Fix if we change that.
int byteOffset = 0; int byteOffset = 0;
BeType* elementType = NULL; BeType* elementType = NULL;
byteOffset += gepConstant->mIdx0 * ptrType->mElementType->mSize; byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride();
if (ptrType->mElementType->mTypeCode == BeTypeCode_Struct) if (ptrType->mElementType->mTypeCode == BeTypeCode_Struct)
{ {
@ -2312,12 +2312,19 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a
elementType = structMember.mType; elementType = structMember.mType;
byteOffset = structMember.mByteOffset; byteOffset = structMember.mByteOffset;
} }
else else if (ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray)
{ {
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray); BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray);
auto arrayType = (BeSizedArrayType*)ptrType->mElementType; auto arrayType = (BeSizedArrayType*)ptrType->mElementType;
elementType = arrayType->mElementType; elementType = arrayType->mElementType;
byteOffset = gepConstant->mIdx1 * elementType->mSize; byteOffset = gepConstant->mIdx1 * elementType->GetStride();
}
else
{
BEMC_ASSERT(ptrType->mElementType->mTypeCode == BeTypeCode_Vector);
auto arrayType = (BeVectorType*)ptrType->mElementType;
elementType = arrayType->mElementType;
byteOffset = gepConstant->mIdx1 * elementType->GetStride();
} }
auto elementPtrType = mModule->mContext->GetPointerTo(elementType); auto elementPtrType = mModule->mContext->GetPointerTo(elementType);