From 6f83cb2905e2cbf6b7822bc714ae1cd4481e3193 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 16 Sep 2015 18:37:48 +0200 Subject: [PATCH] x86: Only skip empty structs on OS X --- gen/abi-x86.cpp | 25 +++++++++++++++++++++++++ gen/functions.cpp | 11 ----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/gen/abi-x86.cpp b/gen/abi-x86.cpp index 1e07392e49..b0c282fc21 100644 --- a/gen/abi-x86.cpp +++ b/gen/abi-x86.cpp @@ -215,6 +215,31 @@ struct X86TargetABI : TargetABI // IMPLICIT PARAMETERS // EXPLICIT PARAMETERS + + // Clang does not pass empty structs, while it seems that GCC does, + // at least on Linux x86. + if (isOSX) + { + size_t i = 0; + while (i < fty.args.size()) + { + Type *type = fty.args[i]->type->toBasetype(); + if (type->ty == Tstruct) + { + // Do not pass empty structs at all for C++ ABI compatibility. + // Tests with clang reveal that more complex "empty" types, for + // example a struct containing an empty struct, are not + // optimized in the same way. + StructDeclaration *sd = static_cast(type)->sym; + if (sd->fields.empty()) + { + fty.args.erase(fty.args.begin() + i); + continue; + } + } + ++i; + } + } } } }; diff --git a/gen/functions.cpp b/gen/functions.cpp index f385f30e97..dc1998ad99 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -164,17 +164,6 @@ llvm::FunctionType* DtoFunctionType(Type* type, IrFuncTy &irFty, Type* thistype, } else if (!passPointer) { - if (loweredDType->toBasetype()->ty == Tstruct) - { - // Do not pass empty structs at all for C++ ABI compatibility. - // Tests with clang reveal that more complex "empty" types, for - // example a struct containing an empty struct, are not - // optimized in the same way. - StructDeclaration *sd = - static_cast(loweredDType->toBasetype())->sym; - if (sd->fields.empty()) continue; - } - if (abi->passByVal(loweredDType)) { attrBuilder.add(LDC_ATTRIBUTE(ByVal));