From c630ab56ff2cac2422825db872f547b8d8295369 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 7 Jul 2012 23:53:46 +0200 Subject: [PATCH] Fix #136 - return static arrays as sret parameters on non-x86. This should eventually be done on x86 and x86_64 as well, but as discussed in GitHub issue #110/pull request #120, the ABI there needs a closer look: at least on x86_64, we need to treat static arrays exactly like if they were a struct containing T.length members of the same type to be compatible with DMD (as soon as the ABI is correctly implemented there, that is). While for this reason I want to avoid a ABI change which could silently break some code only to change the x86 ABI again shortly after, this commit only touches the "default" ABI for unknown targets and thus should be safe (as we give absoultely no ABI guarantees there anyway). --- gen/abi.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gen/abi.cpp b/gen/abi.cpp index ba946222..67761579 100644 --- a/gen/abi.cpp +++ b/gen/abi.cpp @@ -36,7 +36,12 @@ struct UnknownTargetABI : TargetABI if (tf->isref) return false; #endif - return (tf->next->toBasetype()->ty == Tstruct); + // Return structs and static arrays on the stack. The latter is needed + // because otherwise LLVM tries to actually return the array in a number + // of physical registers, which leads, depending on the target, to + // either horrendous codegen or backend crashes. + Type* rt = tf->next->toBasetype(); + return (rt->ty == Tstruct || rt->ty == Tsarray); } bool passByVal(Type* t)