<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Swift does not use the C calling convention.<div class=""><br class=""></div><div class="">-Joe</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 7, 2016, at 10:16 PM, bluedream via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">Hi, all,<br class=""><br class="">I am trying the swift compiler these days in ppc64le, and found that, if the function return type is aggr, the code swift generated didn't conform the ppc64le ABI.<br class=""><br class="">&gt; cat test.swift <br class="">func test() -&gt; (Bool, Double, Int){<br class="">&nbsp;&nbsp;&nbsp; return (true,3.0,3);<br class="">}<br class=""><br class="">test();<br class=""><br class="">&gt; swiftc test.swift -emit-ir<br class="">; ModuleID = '-'<br class="">target datalayout = "e-m:e-i64:64-n32:64"<br class="">target triple = "powerpc64le-unknown-linux-gnu"<br class="">...<br class="">define protected signext i32 @main(i32 signext, i8**) #0 {<br class="">entry:<br class="">&nbsp; %2 = bitcast i8** %1 to i8*<br class="">&nbsp; store i32 %0, i32* getelementptr inbounds (%Vs5Int32, %Vs5Int32* @_TZvOs7Process5_argcVs5Int32, i32 0, i32 0), align 4<br class="">&nbsp; call void @swift_once(i64* @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token3, i8* bitcast (void ()* @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func3 to i8*))<br class="">&nbsp; store i8* %2, i8** getelementptr inbounds (%Sp, %Sp* @_TZvOs7Process11_unsafeArgvGSpGSpVs4Int8__, i32 0, i32 0), align 8<br class="">&nbsp; %3 = call<span style="font-weight: bold;" class=""> { i1, double, i64 }</span> @_TF4test4testFT_TSbSdSi_()<br class="">&nbsp; %4 = extractvalue { i1, double, i64 } %3, 0<br class="">&nbsp; %5 = extractvalue { i1, double, i64 } %3, 1<br class="">&nbsp; %6 = extractvalue { i1, double, i64 } %3, 2<br class="">&nbsp; ret i32 0<br class="">}<br class=""><br class="">We can see that, swift emit the <span style="font-weight: bold;" class=""> { i1, double, i64 } </span>as its return type and llvm will pass the return value of _TF4test4testFT_TSbSdSi_ by register.<br class="">&gt; objdump -dr test.o<br class="">...<br class="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 4c: R_PPC64_TOC16_HA&nbsp;&nbsp;&nbsp; .toc+0x18<br class="">&nbsp; 50:&nbsp;&nbsp;&nbsp; 00 00 63 e8 &nbsp;&nbsp;&nbsp; ld&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r3,0(r3)<br class="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 50: R_PPC64_TOC16_LO_DS&nbsp;&nbsp;&nbsp; .toc+0x18<br class="">&nbsp; 54:&nbsp;&nbsp;&nbsp; 60 00 9f e8 &nbsp;&nbsp;&nbsp; ld&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r4,96(r31)<br class="">&nbsp; 58:&nbsp;&nbsp;&nbsp; 00 00 83 f8 &nbsp;&nbsp;&nbsp; std&nbsp;&nbsp;&nbsp;&nbsp; r4,0(r3)<br class="">&nbsp; 5c:&nbsp;&nbsp;&nbsp; 01 00 00 48 &nbsp;&nbsp;&nbsp; bl&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5c &lt;main+0x5c&gt;<br class="">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 5c: R_PPC64_REL24&nbsp;&nbsp;&nbsp; _TF4test4testFT_TSbSdSi_<br class="">&nbsp; 60:&nbsp;&nbsp;&nbsp; 00 00 00 60 &nbsp;&nbsp;&nbsp; nop<br class=""><br class="">However, for ppc64le ABI, this should be passed by address. See what clang emit the ir for return aggr of this type.<br class=""><br class="">&gt; cat test2.cpp <br class="">struct A {<br class="">bool b;<br class="">double d;<br class="">long long m;<br class="">};<br class=""><br class="">A test();<br class=""><br class="">int main() {<br class="">&nbsp;&nbsp;&nbsp; test();<br class="">&nbsp;&nbsp;&nbsp; return 0;<br class="">}<br class="">&gt; clang test2.cpp -S -emit-llvm <br class="">&gt; cat test2.ll <br class="">; ModuleID = 'test2.cpp'<br class="">target datalayout = "e-m:e-i64:64-n32:64"<br class="">target triple = "powerpc64le-unknown-linux-gnu"<br class=""><br class="">%struct.A = type { i8, double, i64 }<br class=""><br class="">; Function Attrs: norecurse<br class="">define signext i32 @main() #0 {<br class="">&nbsp; %1 = alloca i32, align 4<br class="">&nbsp; %2 = alloca %struct.A, align 8<br class="">&nbsp; store i32 0, i32* %1, align 4<br class="">&nbsp; <span style="font-weight: bold;" class="">call void @_Z4testv(%struct.A* sret %2)</span><br class="">&nbsp; ret i32 0<br class="">}<br class=""><br class="">declare void @_Z4testv(%struct.A* sret) #1<br class=""><br class="">Clang frontend will place it as the first parameter of the function. That would cause serious issues if we are linking with code write from other language(i.e. c/c++). Any comments?<br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></div></body></html>