diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index 28b83f13749ee90eaf2daeaeab5777267a357156..86682b2675ab655fcdc04adf4f7d065ced8b890f 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -115,13 +115,13 @@ void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) { uint64 allocedSize = 0; uint64 allocedSizeInBits = 0; SetStructFieldCount(structType.GetTypeIndex(), fields.size()); - if (fields.size() == 0 && mirModule.IsCModule()) { - SetTypeAlign(tyIdx.GetIdx(), 1); + if (fields.size() == 0) { if (structType.IsCPlusPlus()) { - SetTypeSize(tyIdx.GetIdx(), 1); + SetTypeSize(tyIdx.GetIdx(), 1); // empty struct in C++ has size 1 + SetTypeAlign(tyIdx.GetIdx(), 1); } else { - /* empty struct is not supported in C, but gcc allows for it as size 0 */ SetTypeSize(tyIdx.GetIdx(), 0); + SetTypeAlign(tyIdx.GetIdx(), 8); } return; } diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index ea07f8115593da4991387ba1c619eefb61a5975a..057b83020240b172dcc5276de614ad6fdc0a5d81 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -660,8 +660,10 @@ BlockNode *CGLowerer::LowerReturnStruct(NaryStmtNode &retNode) { retNode.SetOpnd(LowerExpr(retNode, *retNode.GetNopndAt(i), *blk), i); } BaseNode *opnd0 = retNode.Opnd(0); - CHECK_FATAL(opnd0 != nullptr, "return struct should have a kid"); - CHECK_FATAL(opnd0->GetPrimType() == PTY_agg, "return struct should have a kid"); + if (!(opnd0 && opnd0->GetPrimType() == PTY_agg)) { + // It is possible function never returns and have a dummy return const instead of a struct. + maple::LogInfo::MapleLogger(kLlWarn) << "return struct should have a kid" << std::endl; + } MIRFunction *curFunc = GetCurrentFunc(); MIRSymbol *retSt = curFunc->GetFormal(0); @@ -1388,7 +1390,9 @@ StmtNode *CGLowerer::LowerCall(CallNode &callNode, StmtNode *&nextStmt, BlockNod MIRSymbol *dsgnSt = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dassignNode->GetStIdx()); CHECK_FATAL(dsgnSt->GetType()->IsStructType(), "expects a struct type"); MIRStructType *structTy = static_cast(dsgnSt->GetType()); - CHECK_FATAL(structTy != nullptr, "expects that the assignee variable should have a struct type"); + if (structTy == nullptr) { + return &callNode; + } RegreadNode *regReadNode = nullptr; if (dassignNode->Opnd(0)->GetOpCode() == OP_regread) { diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index cd80ccd99c1c15d962cd7b6c6084205c761f52df..0d5a6fe9bc11280ab0662d276593cc54d834aa5f 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -1134,11 +1134,6 @@ void AArch64CGFunc::SelectIassign(IassignNode &stmt) { isRefField = true; /* write into an object array or a high-dimensional array */ } } - if (pointedType->GetPrimType() == PTY_agg) { - maple::LogInfo::MapleLogger(kLlErr) << "Error: cannot find field in " << - GlobalTables::GetStrTable().GetStringFromStrIdx(pointedType->GetNameStrIdx()) << '\n'; - exit(-1); - } } PrimType styp = stmt.GetRHS()->GetPrimType(); @@ -1821,6 +1816,10 @@ Operand *SelectLiteral(T *c, MIRFunction *func, uint32 labelIdx, AArch64CGFunc * st->SetTyIdx(TyIdx(primType)); uint32 typeBitSize = GetPrimTypeBitSize(primType); + if (cgFunc->GetMirModule().IsCModule() && + (T::GetPrimType() == PTY_f32 || T::GetPrimType() == PTY_f64)) { + return static_cast(&cgFunc->GetOrCreateMemOpnd(*st, 0, typeBitSize)); + } if (T::GetPrimType() == PTY_f32) { return (fabs(c->GetValue()) < std::numeric_limits::denorm_min()) ? static_cast(&cgFunc->GetOrCreateFpZeroOperand(typeBitSize)) diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 6d8e497b2d3c7ca786c1a8f40805aab9ac6510d7..408adb5b411b9659eb799c714b56a9d6a950607d 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -286,9 +286,14 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) { Emit(size); Emit(", "); #if PECOFF +#if TARGARM || TARGAARCH64 || TARGARK || TARGRISCV64 std::string align = std::to_string( static_cast(log2(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())))); - emit(align); +#else + std::string align = std::to_string( + Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex())); +#endif + emit(align.c_str()); #else /* ELF */ /* output align, symbol name begin with "classInitProtectRegion" align is 4096 */ MIRTypeKind kind = mirSymbol.GetType()->GetKind(); @@ -297,7 +302,12 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) { Emit(4096); } else if (((kind == kTypeStruct) || (kind == kTypeClass) || (kind == kTypeArray) || (kind == kTypeUnion)) && ((storage == kScGlobal) || (storage == kScPstatic) || (storage == kScFstatic))) { - Emit(std::to_string(k8ByteSize)); + int32 align = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex()); + if (kSizeOfPtr < align) { + Emit(std::to_string(align)); + } else { + Emit(std::to_string(k8ByteSize)); + } } else { Emit(std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex()))); }