If you could point me towards the correct location in the standard I would appreciate that - I didn't realize it wasn't acceptable to turn pointer-data to structs. My example is reduced from the EEMBC benchmarks where I ran into the problem, so I may have reduced it too far by accident (but I'm fairly sure they do not use __attribute__ or similar).<div>
<br></div><div>Adding a __attribute__((aligned(...))) to my example did help, so thank you for that! Now to determine what to do about EEMBC...<br><div><br></div><div>Thanks,<br>Stephen<br><div><br><div class="gmail_quote">
On 12 October 2012 21:01, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Fri, Oct 12, 2012 at 10:43 AM, Stephen McGruer<br>
<<a href="mailto:stephen.mcgruer@gmail.com">stephen.mcgruer@gmail.com</a>> wrote:<br>
> I'm having trouble getting my backend to properly treat the situation where<br>
> a char* is converted into a struct, i.e. something like:<br>
><br>
> char* pointer_representation = ...;<br>
> MyStruct* my_struct = (MyStruct*) pointer_representation;<br>
> my_struct->an_int_field = 5;<br>
><br>
> When this occurs, LLVM seems to fold the struct and char* into one assembly<br>
> 'object', which is perfectly fine. However, it also keeps the 1-alignment of<br>
> the char array, which is not ok, as then the assignment (store) to the<br>
> 'an_int_field' gets converted into a 4-byte aligned store instruction -<br>
> which of course fails when run.<br>
><br>
> My test case can be seen at <a href="http://pastebin.com/zPTi2GRW" target="_blank">http://pastebin.com/zPTi2GRW</a>. Does anyone know<br>
> what I might need to do in my backend to make this work properly - perhaps<br>
> correct the definition of my 'store' instructions, or set a data-layout for<br>
> a struct type somewhere?<br>
<br>
</div></div>Your code has undefined behavior; you're just getting lucky if it<br>
works anywhere.  (I can look up the standard reference if you're<br>
interested.)  Try __attribute((aligned)) on the array.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Eli<br>
</font></span></blockquote></div><br></div></div></div>