<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 <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> 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="">> cat test.swift <br class="">func test() -> (Bool, Double, Int){<br class=""> return (true,3.0,3);<br class="">}<br class=""><br class="">test();<br class=""><br class="">> 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=""> %2 = bitcast i8** %1 to i8*<br class=""> store i32 %0, i32* getelementptr inbounds (%Vs5Int32, %Vs5Int32* @_TZvOs7Process5_argcVs5Int32, i32 0, i32 0), align 4<br class=""> call void @swift_once(i64* @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token3, i8* bitcast (void ()* @globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func3 to i8*))<br class=""> store i8* %2, i8** getelementptr inbounds (%Sp, %Sp* @_TZvOs7Process11_unsafeArgvGSpGSpVs4Int8__, i32 0, i32 0), align 8<br class=""> %3 = call<span style="font-weight: bold;" class=""> { i1, double, i64 }</span> @_TF4test4testFT_TSbSdSi_()<br class=""> %4 = extractvalue { i1, double, i64 } %3, 0<br class=""> %5 = extractvalue { i1, double, i64 } %3, 1<br class=""> %6 = extractvalue { i1, double, i64 } %3, 2<br class=""> 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="">> objdump -dr test.o<br class="">...<br class=""> 4c: R_PPC64_TOC16_HA .toc+0x18<br class=""> 50: 00 00 63 e8 ld r3,0(r3)<br class=""> 50: R_PPC64_TOC16_LO_DS .toc+0x18<br class=""> 54: 60 00 9f e8 ld r4,96(r31)<br class=""> 58: 00 00 83 f8 std r4,0(r3)<br class=""> 5c: 01 00 00 48 bl 5c <main+0x5c><br class=""> 5c: R_PPC64_REL24 _TF4test4testFT_TSbSdSi_<br class=""> 60: 00 00 00 60 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="">> 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=""> test();<br class=""> return 0;<br class="">}<br class="">> clang test2.cpp -S -emit-llvm <br class="">> 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=""> %1 = alloca i32, align 4<br class=""> %2 = alloca %struct.A, align 8<br class=""> store i32 0, i32* %1, align 4<br class=""> <span style="font-weight: bold;" class="">call void @_Z4testv(%struct.A* sret %2)</span><br class=""> 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>