diff --git a/src/mapleall/maple_be/include/be/becommon.h b/src/mapleall/maple_be/include/be/becommon.h index 89092fc5db8260c33167a232613de70f9d42f31e..baceed351c588b7415042fb46d601274d989fc2a 100644 --- a/src/mapleall/maple_be/include/be/becommon.h +++ b/src/mapleall/maple_be/include/be/becommon.h @@ -143,7 +143,7 @@ class BECommon { } /* Global type table might be updated during lowering for C/C++. */ - void FinalizeTypeTable(); + void FinalizeTypeTable(MIRType &ty); uint32 GetFieldIdxIncrement(const MIRType &ty) const { if (ty.GetKind() == kTypeClass) { diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index 28b83f13749ee90eaf2daeaeab5777267a357156..2179f1e1d74beccd370043e9e1512038ae35dd4c 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -608,7 +608,7 @@ bool BECommon::TyIsInSizeAlignTable(const MIRType &ty) const { } void BECommon::AddAndComputeSizeAlign(MIRType &ty) { - CHECK_FATAL(ty.GetTypeIndex() == typeSizeTable.size(), "make sure the ty idx is exactly the table size"); + FinalizeTypeTable(ty); typeAlignTable.emplace_back(mirModule.IsCModule()); typeSizeTable.emplace_back(0); ComputeTypeSizesAligns(ty); @@ -643,12 +643,15 @@ MIRType *BECommon::BeGetOrCreateFunctionType(TyIdx tyIdx, const std::vector GetSizeOfTypeSizeTable())) { - for (uint32 i = GetSizeOfTypeSizeTable(); i < GlobalTables::GetTypeTable().GetTypeTableSize(); ++i) { - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(i); - AddAndComputeSizeAlign(*ty); +void BECommon::FinalizeTypeTable(MIRType &ty) { + if (ty.GetTypeIndex() > GetSizeOfTypeSizeTable()) { + if (mirModule.GetSrcLang() == kSrcLangC) { + for (uint32 i = GetSizeOfTypeSizeTable(); i < ty.GetTypeIndex(); ++i) { + MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(i); + AddAndComputeSizeAlign(*ty); + } + } else { + CHECK_FATAL(ty.GetTypeIndex() == typeSizeTable.size(), "make sure the ty idx is exactly the table size"); } } } diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index ea07f8115593da4991387ba1c619eefb61a5975a..1b171ad4635fc31f7b19f284a3d328171b41ef46 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -829,7 +829,7 @@ StmtNode *CGLowerer::LowerIassignBitfield(IassignNode &iassign, BlockNode &newBl DepositbitsNode *depositBits = mirModule.CurFuncCodeMemPool()->New(); depositBits->SetPrimType(GetRegPrimType(fType->GetPrimType())); depositBits->SetBitsOffset(byteBitOffsets.second); - depositBits->SetBitsOffset(static_cast(fType)->GetFieldSize()); + depositBits->SetBitsSize(static_cast(fType)->GetFieldSize()); depositBits->SetBOpnd(ireadNode, 0); depositBits->SetBOpnd(iassign.GetRHS(), 1); @@ -3019,7 +3019,6 @@ void CGLowerer::LowerFunc(MIRFunction &func) { CHECK_FATAL(origBody != nullptr, "origBody should not be nullptr"); BlockNode *newBody = LowerBlock(*origBody); - beCommon.FinalizeTypeTable(); func.SetBody(newBody); if (needBranchCleanup) { CleanupBranches(func); diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp index c4bf2b166979c142a0d5569352a7567fe492b203..ce16ce9f7264d869721d9e011592cc340bbdce8b 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_insn.cpp @@ -741,7 +741,7 @@ void AArch64Insn::EmitAdrpLabel(Emitter &emitter) const { emitter.Emit(", "); const char *idx; idx = strdup(std::to_string(Globals::GetInstance()->GetBECommon()->GetMIRModule().CurFunction()->GetPuidx()).c_str()); - emitter.Emit(".label.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); + emitter.Emit(".L.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); /* add xd, xd, #lo12:label */ emitter.Emit("\tadd\t"); @@ -749,7 +749,7 @@ void AArch64Insn::EmitAdrpLabel(Emitter &emitter) const { emitter.Emit(", "); opnd0->Emit(emitter, prop0); emitter.Emit(", "); - emitter.Emit(":lo12:").Emit(".label.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); + emitter.Emit(":lo12:").Emit(".L.").Emit(idx).Emit("__").Emit(lidx).Emit("\n"); emitter.Emit("\n"); } diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 6d8e497b2d3c7ca786c1a8f40805aab9ac6510d7..0260ee5692aa259443fb5eb367dece3384bc8410 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -1504,6 +1504,9 @@ void Emitter::EmitStructConstant(MIRConst &mirConst) { /* total size of emitted elements size. */ uint32 size = Globals::GetInstance()->GetBECommon()->GetTypeSize(structType.GetTypeIndex()); uint32 fieldIdx = 1; + if (structType.GetKind() == kTypeUnion) { + fieldIdx = structCt.GetConstVecItem(0)->GetFieldId(); + } for (uint32 i = 0; i < num; ++i) { if (((i + 1) == num) && cg->GetMIRModule()->GetSrcLang() == kSrcLangC) { isFlexibleArray = Globals::GetInstance()->GetBECommon()->GetHasFlexibleArray(mirType.GetTypeIndex().GetIdx()); diff --git a/src/mapleall/maple_ir/src/mir_parser.cpp b/src/mapleall/maple_ir/src/mir_parser.cpp index 0f0392eec4ebf63cd70345ce143fd2b1e9e5a62c..6cc71d554060146c680a332b80808faaf5731bc7 100644 --- a/src/mapleall/maple_ir/src/mir_parser.cpp +++ b/src/mapleall/maple_ir/src/mir_parser.cpp @@ -2606,7 +2606,7 @@ bool MIRParser::ParseScalarValue(MIRConstPtr &stype, MIRType &type) { Error("constant value incompatible with integer type at "); return false; } - stype = GlobalTables::GetIntConstTable().GetOrCreateIntConst(lexer.GetTheIntVal(), type); + stype = mod.GetMemPool()->New(lexer.GetTheIntVal(), type); } else if (ptp == PTY_f32) { if (lexer.GetTokenKind() != TK_floatconst) { Error("constant value incompatible with single-precision float type at ");