From: Anders Carlsson Date: Wed, 27 Jan 2010 03:25:19 +0000 (+0000) Subject: Structs and classes with non-trivial destructors or copy constructors should be passe... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a887423cf580e19b2d03e3a0499c065730c96b28;p=clang Structs and classes with non-trivial destructors or copy constructors should be passed indirectly in the 32-bit ABI. Fixes PR6094. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94656 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 4454662a93..bc512e7a27 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -358,6 +358,8 @@ bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty, const RecordType *RT = Ty->getAs(); if (!RT) return false; + // FIXME: Traverse bases here too. + // Structure types are passed in register if all fields would be // passed in a register. for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(), @@ -404,7 +406,7 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, return ABIArgInfo::getDirect(); } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { - if (const RecordType *RT = RetTy->getAsStructureType()) { + if (const RecordType *RT = RetTy->getAs()) { // Structures with either a non-trivial destructor or a non-trivial // copy constructor are always indirect. if (hasNonTrivialDestructorOrCopyConstructor(RT)) @@ -484,10 +486,16 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, // FIXME: Set alignment on indirect arguments. if (CodeGenFunction::hasAggregateLLVMType(Ty)) { // Structures with flexible arrays are always indirect. - if (const RecordType *RT = Ty->getAsStructureType()) + if (const RecordType *RT = Ty->getAs()) { + // Structures with either a non-trivial destructor or a non-trivial + // copy constructor are always indirect. + if (hasNonTrivialDestructorOrCopyConstructor(RT)) + return ABIArgInfo::getIndirect(0, /*ByVal=*/false); + if (RT->getDecl()->hasFlexibleArrayMember()) return ABIArgInfo::getIndirect(getIndirectArgumentAlignment(Ty, Context)); + } // Ignore empty structs. if (Ty->isStructureType() && Context.getTypeSize(Ty) == 0)