From d86e5308c15babc138c23447e3cb3f2eda657877 Mon Sep 17 00:00:00 2001 From: Alfred Huang Date: Wed, 31 Mar 2021 15:28:46 -0700 Subject: [PATCH] Fixed agg arraytype in GetFieldOffset --- src/mapleall/maple_be/src/be/becommon.cpp | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index ec475deafd..60f57287c7 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -140,9 +140,9 @@ void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) { uint8 fieldAlign = GetTypeAlign(fieldTyIdx); uint64 fieldAlignBits = fieldAlign * kBitsPerByte; CHECK_FATAL(fieldAlign != 0, "expect fieldAlign not equal 0"); - if ((fieldType->GetKind() == kTypeStruct) || (fieldType->GetKind() == kTypeClass) || - (fieldType->GetKind() == kTypeUnion)) { - AppendStructFieldCount(structType.GetTypeIndex(), GetStructFieldCount(fieldTyIdx)); + MIRStructType *subStructType = fieldType->EmbeddedStructType(); + if (subStructType != nullptr) { + AppendStructFieldCount(structType.GetTypeIndex(), GetStructFieldCount(subStructType->GetTypeIndex())); } if (structType.GetKind() != kTypeUnion) { if (fieldType->GetKind() == kTypeBitField) { @@ -614,14 +614,15 @@ std::pair BECommon::GetFieldOffset(MIRStructType &structType, Fiel return std::pair(offset, 0); } else { MIRStructType *subStructType = fieldType->EmbeddedStructType(); - if (subStructType != nullptr) { - if ((curFieldID + GetStructFieldCount(fieldTyIdx)) >= fieldID) { + if (subStructType == nullptr) { + ++curFieldID; + } else { + if ((curFieldID + GetStructFieldCount(subStructType->GetTypeIndex())) < fieldID) { + curFieldID += GetStructFieldCount(subStructType->GetTypeIndex()) + 1; + } else { std::pair result = GetFieldOffset(*subStructType, fieldID - curFieldID); return std::pair(result.first + allocedSize, result.second); } - curFieldID += GetStructFieldCount(fieldTyIdx) + 1; - } else { - ++curFieldID; } } @@ -637,14 +638,14 @@ std::pair BECommon::GetFieldOffset(MIRStructType &structType, Fiel if (curFieldID == fieldID) { return std::pair(0, 0); } else { - MIRStructType *subStructTy = fieldType->EmbeddedStructType(); - if (subStructTy == nullptr) { + MIRStructType *subStructType = fieldType->EmbeddedStructType(); + if (subStructType == nullptr) { curFieldID++; } else { - if ((curFieldID + GetStructFieldCount(subStructTy->GetTypeIndex())) < fieldID) { - curFieldID += GetStructFieldCount(subStructTy->GetTypeIndex()) + 1; + if ((curFieldID + GetStructFieldCount(subStructType->GetTypeIndex())) < fieldID) { + curFieldID += GetStructFieldCount(subStructType->GetTypeIndex()) + 1; } else { - return GetFieldOffset(*subStructTy, fieldID - curFieldID); + return GetFieldOffset(*subStructType, fieldID - curFieldID); } } } -- Gitee