[LLVMdev] Problem in llvm gcc back-end

quho armbox at gmail.com
Sun May 27 23:38:41 PDT 2007


Hi,

I'm sorry,
I found it on bugzilla database..

http://llvm.org/bugs/show_bug.cgi?id=1421

And there was instruction for fix it.

Thanks
Quho

2007/5/28, quho <armbox at gmail.com>:
> HI,
>
> While I testing some code, I found some problem on Union handling.
>
> I've wrte following test code, and it has union assignment.
>
> The code's output is
>
> from pointerToUnion: chars mystring, length 64
> from original: chars mystring, length 8000
>
> It's caused by second char member(charlength) of LongestMember.
>
> For union assignment, llvm-backend seems generates assigning each
> member of largest union member. (I've checked it on llvm assembly
> level..)
> But sometimes there is padding between members and it's different for members.
>
> So in my opinion you should handle union assignment as pseudo array of
> word(or byte).
> (it's same for argument passing..)
>
>
> =====================================================
> #include <stdio.h>
>
> struct MyString {
>     char *chars;
>     int length;
> };
>
> struct LongestMember {
>     char *chars;
>     char charlength;
>     int empty1;
>     int empty2;
> };
>
> typedef union {
>     MyString string;
>     LongestMember mt;
> } UnionType;
>
>
> int main() {
>     UnionType original;
>     UnionType *pointerToUnion;
>     UnionType buffer;
>
>     pointerToUnion = &buffer;
>
>     original.string.chars = "mystring";
>     original.string.length = 8000;
>
>     *pointerToUnion = original;
>
>     printf("from pointerToUnion: chars %s, length %d\n",
> pointerToUnion->string.chars, pointerToUnion->string.length);
>     printf("from original: chars %s, length %d\n",
> original.string.chars, original.string.length);
> }
> =====================================================
>
>
> Thanks,
> Quho.
>


-- 
Armbox.



More information about the llvm-dev mailing list