From 0c276600f553f8b94c62aed37d27978d1ee47b86 Mon Sep 17 00:00:00 2001 From: Alfred Huang Date: Mon, 1 Mar 2021 16:28:17 -0800 Subject: [PATCH] Miscellanenous merge of commits 40c58aa, 17b1b03, ab5de00 --- src/mapleall/maple_be/src/be/becommon.cpp | 11 ++++++++--- src/mapleall/maple_be/src/be/lower.cpp | 10 +++++++--- .../maple_be/src/cg/aarch64/aarch64_cgfunc.cpp | 9 ++++----- src/mapleall/maple_be/src/cg/emit.cpp | 14 ++++++++++++-- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/mapleall/maple_be/src/be/becommon.cpp b/src/mapleall/maple_be/src/be/becommon.cpp index ba35b57fc3..d176dcaaed 100644 --- a/src/mapleall/maple_be/src/be/becommon.cpp +++ b/src/mapleall/maple_be/src/be/becommon.cpp @@ -115,9 +115,14 @@ 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); - SetTypeSize(tyIdx.GetIdx(), 1); + if (fields.size() == 0) { + if (structType.IsCPlusPlus()) { + SetTypeSize(tyIdx.GetIdx(), 1); // empty struct in C++ has size 1 + SetTypeAlign(tyIdx.GetIdx(), 1); + } else { + SetTypeSize(tyIdx.GetIdx(), 0); + SetTypeAlign(tyIdx.GetIdx(), 8); + } return; } for (size_t j = 0; j < fields.size(); ++j) { diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index 2aa8bf469c..b3ed9fe75c 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -505,8 +505,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); @@ -1220,7 +1222,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 8b2820a187..4e61f6c3cb 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 c9451cea9a..55e1114a1a 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()))); } -- Gitee