Fix the ABI convention for struct returns on x86 outside of Darwin.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67577 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index d7f52c6..8c438c9 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -251,6 +251,8 @@
/// X86_32ABIInfo - The X86-32 ABI information.
class X86_32ABIInfo : public ABIInfo {
+ bool IsDarwin;
+
public:
ABIArgInfo classifyReturnType(QualType RetTy,
ASTContext &Context) const;
@@ -267,6 +269,8 @@
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
CodeGenFunction &CGF) const;
+
+ X86_32ABIInfo(bool d) : ABIInfo(), IsDarwin(d) {}
};
}
@@ -275,6 +279,9 @@
if (RetTy->isVoidType()) {
return ABIArgInfo::getIgnore();
} else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
+ // Outside of Darwin, structs and unions are always indirect.
+ if (!IsDarwin && !RetTy->isAnyComplexType())
+ return ABIArgInfo::getIndirect(0);
// Classify "single element" structs as their element type.
const FieldDecl *SeltFD = isSingleElementStruct(RetTy);
if (SeltFD) {
@@ -1183,9 +1190,10 @@
// to free it.
const char *TargetPrefix = getContext().Target.getTargetPrefix();
if (strcmp(TargetPrefix, "x86") == 0) {
+ bool IsDarwin = strstr(getContext().Target.getTargetTriple(), "darwin");
switch (getContext().Target.getPointerWidth(0)) {
case 32:
- return *(TheABIInfo = new X86_32ABIInfo());
+ return *(TheABIInfo = new X86_32ABIInfo(IsDarwin));
case 64:
return *(TheABIInfo = new X86_64ABIInfo());
}