Problem using 'bitcast'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem using 'bitcast'

Dave Cope
I have been trying to compile some Llvm code that I generate, and I am running into a problem assembling my ll code.  Here is a snippet of the code I am trying to compile:
    %loc0 = alloca i32
    call void @llvm.dbg.declare( {  }* bitcast(i32* %loc0 to {  }*), {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

I get an error from the second line of code:
    Invalid reference to global

Just to try to get the code to compile, I replaced the reference to %loc0 with null:
    %loc0 = alloca i32
    call void @llvm.dbg.declare( {  }* bitcast(i32* null to {  }*), {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

This code compiles fine, but obviously will not give the end result I want.

My current solution is to introduce a temporary variable like this:
    %loc0 = alloca i32
    %loc0_void = bitcast i32* %loc0 to {  }*
    call void @llvm.dbg.declare( {  }* %loc0_void, {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

I would prefer to make the first code snippet work (to avoid adding temporary variables and cluttering up the ll code).  But my workaround is alright for now.

I am wondering why my first code snippet doesn't compile properly.  Am I doing something incorrect?  Or is this possibly and LLVM bug of some kind?

Thanks a lot,
Dave Cope


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Problem using 'bitcast'

Daniel Dunbar
>    call void @llvm.dbg.declare( {  }* bitcast(i32* %loc0 to {  }*), {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

This is not legal. The distinction here is that the bitcast as an argument is
a constant expression and requires constant arguments, and %loc0 is not constant.
Introducing the temp variable is the "right way" to do this.

 - Daniel

----- Original Message ----
From: Dave Cope <[hidden email]>
To: [hidden email]
Sent: Friday, April 4, 2008 10:11:30 AM
Subject: [LLVMdev] Problem using 'bitcast'

I have been trying to compile some Llvm code that I generate, and I am running into a problem assembling my ll code.  Here is a snippet of the code I am trying to compile:
    %loc0 = alloca i32
    call void @llvm.dbg.declare( {  }* bitcast(i32* %loc0 to {  }*), {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

I get an error from the second line of code:
    Invalid reference to global

Just to try to get the code to compile, I replaced the reference to %loc0 with null:
    %loc0 = alloca i32
    call void @llvm.dbg.declare( {  }* bitcast(i32* null to {  }*), {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

This code compiles fine, but obviously will not give the end result I want.

My current solution is to introduce a temporary variable like this:
    %loc0 = alloca i32
    %loc0_void = bitcast i32* %loc0 to {  }*
    call void @llvm.dbg.declare( {  }* %loc0_void, {  }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable1 to {  }*) )

I would prefer to make the first code snippet work (to avoid adding temporary variables and cluttering up the ll code).  But my workaround is alright for now.

I am wondering why my first code snippet doesn't compile properly.  Am I doing something incorrect?  Or is this possibly and LLVM bug of some kind?

Thanks a lot,
Dave Cope





_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev