From a8b196bc4fdb2e715969987f831074efbebc310f Mon Sep 17 00:00:00 2001 From: "Alon Zakai (kripken)" Date: Mon, 10 Apr 2017 11:35:15 -0700 Subject: [PATCH] fix optimization of struct returns when there is a constructor, update ABI code to match wasm's which we are following --- lib/CodeGen/TargetInfo.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 5389dfd5bca..87f4eefec74 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -708,10 +708,18 @@ ABIArgInfo EmscriptenABIInfo::classifyArgumentType(QualType Ty) const { ABIArgInfo EmscriptenABIInfo::classifyReturnType(QualType RetTy) const { if (isAggregateTypeForABI(RetTy)) { - // As an optimization, lower single-element structs to just return a regular - // value. - if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) - return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); + // Records with non-trivial destructors/copy-constructors should not be + // returned by value. + if (!getRecordArgABI(RetTy, getCXXABI())) { + // Ignore empty structs/unions. + if (isEmptyRecord(getContext(), RetTy, true)) + return ABIArgInfo::getIgnore(); + // Lower single-element structs to just return a regular value. TODO: We + // could do reasonable-size multiple-element structs too, using + // ABIArgInfo::getDirect(). + if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) + return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); + } } // Otherwise just do the default thing.