<div dir="ltr">I can confirm that, with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)<div><br></div><div>Very strange!</div><div><br></div><div>I don't know if it helps you, but this looks correct:</div><div><br></div><div><div>typedef struct {float v0, v1;} vec2;</div><div>typedef struct {float v0, v1, v2;} vec3;</div><div><br></div><div>vec2 getVec2();</div><div><br></div><div>vec3 getVec3()</div><div>{</div><div> vec2 myVec = getVec2();</div><div><br></div><div> vec3 res;</div><div> res.v0 = myVec.v0;</div><div> res.v1 = myVec.v1;</div><div> res.v2 = 1;</div><div> return res;</div><div>}</div></div><div><br></div><div><div><span class="" style="white-space:pre"> </span>.section<span class="" style="white-space:pre"> </span>__TEXT,__text,regular,pure_instructions</div><div><span class="" style="white-space:pre"> </span>.globl<span class="" style="white-space:pre"> </span>_getVec3</div><div><span class="" style="white-space:pre"> </span>.align<span class="" style="white-space:pre"> </span>2</div><div>_getVec3: ; @getVec3</div><div>; BB#0:</div><div><span class="" style="white-space:pre"> </span>stp<span class="" style="white-space:pre"> </span>fp, lr, [sp, #-16]!</div><div><span class="" style="white-space:pre"> </span>mov<span class="" style="white-space:pre"> </span> fp, sp</div><div><span class="" style="white-space:pre"> </span>bl<span class="" style="white-space:pre"> </span>_getVec2</div><div><span class="" style="white-space:pre"> </span>fmov<span class="" style="white-space:pre"> </span>s2, #1.000000e+00</div><div><span class="" style="white-space:pre"> </span>ldp<span class="" style="white-space:pre"> </span>fp, lr, [sp], #16</div><div><span class="" style="white-space:pre"> </span>ret</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 1:19 PM, Simon Taylor <span dir="ltr"><<a href="mailto:simontaylor1@ntlworld.com" target="_blank">simontaylor1@ntlworld.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I’ve narrowed down a problem in my code to the following test case:<br>
<br>
- - - -<br>
<br>
typedef struct {float v[2];} vec2;<br>
typedef struct {float v[3];} vec3;<br>
<br>
vec2 getVec2();<br>
<br>
vec3 getVec3()<br>
{<br>
vec2 myVec = getVec2();<br>
<br>
vec3 res;<br>
res.v[0] = myVec.v[0];<br>
res.v[1] = myVec.v[1];<br>
res.v[2] = 1;<br>
return res;<br>
}<br>
<br>
- - - -<br>
<br>
Compiling this with any level of optimization for arm64 gives incorrect code, unless my test case above is triggering some undefined behaviour that I’m not aware of. Other architectures appear to work OK.<br>
<br>
$ clang -arch arm64 -O1 test.c -S -o -<br>
.section __TEXT,__text,regular,pure_instructions<br>
.ios_version_min 5, 0<br>
.globl _getVec3<br>
.align 2<br>
_getVec3: ; @getVec3<br>
; BB#0:<br>
b _getVec2<br>
<br>
<br>
.subsections_via_symbols<br>
<br>
- - - -<br>
<br>
I’m happy to file a bug for this, but not sure quite where it belongs - clang, LLVM or direct to Apple. Can someone test the top of tree and see if it suffers the same issue?<br>
<br>
I’m currently using the latest Xcode from Apple (clang -v gives “Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)”) but the LLVM 3.5-based compiler in the previous Xcode release also generates the same code.<br>
<br>
<br>
Simon<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>