[LLVMdev] Loss of Type information

Santosh Nagarakatte santosh.nagarakatte at gmail.com
Sun May 10 11:44:14 PDT 2009

I have a struct node with three fields {size_t, size_t, struct node *}. When
I allocate such a node, malloc allocates [3* i64] i.e allocates an array of
3 i64's but not a structure.
Thus any store to the pointer field in the structures involves a cast from a
pointer to an integer.
So a pointer is cast to a integer and then stored into the third field of
this structure.
This happens only when I use llvm-gcc -O3 to generate the bitcode? why does
llvm-gcc do this with -O3?

Sample bitcode illustrating the same is shown below.

        %2 = malloc [3 x i64]           ; <[3 x i64]*> [#uses=6]
        %.sub = getelementptr [3 x i64]* %2, i64 0, i64 0               ;
<i64*> [#uses=\
        store i64 %i.0.reg2mem.0, i64* %.sub, align 8
        %3 = getelementptr [3 x i64]* %2, i64 0, i64 1          ; <i64*>
        %.c = add i64 %i.0.reg2mem.0, 1         ; <i64> [#uses=3]
        store i64 %.c, i64* %3
        %4 = getelementptr [3 x i64]* %2, i64 0, i64 2          ; <i64*>
        %ptr.0.c = ptrtoint [3 x i64]* %ptr.0.in.in.reg2mem.0 to
i64            ; <i64> \
        store i64 %ptr.0.c, i64* %4

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090510/784fb278/attachment.html>

More information about the llvm-dev mailing list