[LLVMdev] Problems of manipulating GEP for struct type

Duncan Sands baldrick at free.fr
Thu Oct 4 00:32:40 PDT 2012


Hi Chia Lun,

On 04/10/12 07:58, ChiaLun wrote:
> Hi,
>
> I use JIT to execute the following LLVM IR,
>
> ------------------------------------------------------------------------------------------------------------
> define internal fastcc i32 @L_00008120_(%struct.ThreadContext* %ThreadCtx) {

does the caller also specify the fastcc calling convention when calling this?

Ciao, Duncan.

> L_00000000_:
>    %0 = alloca i32
>    %1 = alloca i32
>    %2 = alloca %struct.ThreadContext*, align 4
>    store %struct.ThreadContext* %ThreadCtx, %struct.ThreadContext** %2
>    call void @reach()
>    br label %L_00008120_
>
> L_00008120_:                                      ; preds = %L_00000000_
>    call void @reach()
>    %3 = load %struct.ThreadContext** %2, align 4
>    call void @reach()
>    %4 = getelementptr inbounds %struct.ThreadContext* %3, i32 0, i32 1
>    call void @reach()
>    %5 = getelementptr inbounds [32 x i32]* %4, i32 0, i32 2
>    call void @reach()
> *  store i32 33056, i32* %5*
>    call void @reach()
>    br label %L_00008120_1
>
>
> .....
>
> --------------------------------------------------------------------------------------------------
>
>
> Somehow, the storeInst is not successfully performed, it gets
>
> segmentation fault, I wonder if I miss something important.
>
>
>
> I pinpoint the problems by inserting call void @reach(), before each
> instructions,
>
> the codes for function reach are
>
> void reach()
> {
>    puts("press any key");
>      getchar();
> 	puts("reach");
> 	fprintf(stderr,"reach stderr\n");
> }
>
> so I am almost sure that the segmentation fault is derived from storeInst.
>
>
>
> the structure struct.ThreadContext in LLVM IR corresponds to C struct
>
> struct ThreadContext
> {
>      int id;
>      int r[32];
>
>
>      void init();
>      void setsp(int);
>      void setpc(int);
> };
>
>
> The function prototype
> typedef uint32_t (*func)(struct ThreadContext* );
>
> func = jit->runJITOnFunction(...);
>
> then execute the function by
>
> func(&ctx); // ctx is defined to be " struct ThreadContext ctx;"
>
>
>
> My execution result
>
> press any key
>
> reach
> reach stderr
> press any key
>
> reach
> reach stderr
> press any key
>
> reach
> reach stderr
> press any key
>
> reach
> reach stderr
> press any key
>
> reach
> reach stderr
> 0  libDynTrans.so 0x013650b8
> Stack dump:
> 0.	Program arguments: ./Release+Asserts/bin/translator
> ../testcase/print_arm2011
> Segmentation fault
>
>
> If anyone can give a hint on the possible reason of segmentation fault, I
> would be grateful.
>
> Chia Lun
>
>
>
>
>
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Problems-of-manipulating-GEP-for-struct-type-tp49616.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list