Hi, I'm trying to define a mutable variable, outside functions. The code below is trying to evaluate an expression much like "x = 1" at the module level in Python. It appears that when it tries to JIT the function there is an error because there is no storage allocated for 'x'. How do I do that? thanks, Rob ----- dumped IR ----- ; ModuleID = 'repl-module' %0 = type opaque @x = external global %0* define %0* @0() { entry: store %0* inttoptr (i64 4316154480 to %0*), %0** @x ret %0* inttoptr (i64 4316154480 to %0*) } LLVM ERROR: Could not resolve external global address: x ----- C++ code ----- GlobalVariable *gvar = new GlobalVariable(*module, id_ty, false, GlobalVariable::ExternalLinkage, 0, str.str()); Value *valv = gen_expr(val); builder.CreateStore(valv, gvar, false); ... engine->getPointerToFunction(thunk);
On 12 January 2011 22:28, Rob Nikander <rob.nikander at gmail.com> wrote:> @x = external global %0*Hi Rob, Try removing the 'extern', as it implies the variable storage is elsewhere (ie. another object file). cheers, --renato
On Wed, Jan 12, 2011 at 6:08 PM, Renato Golin <rengolin at systemcall.org> wrote:> On 12 January 2011 22:28, Rob Nikander <rob.nikander at gmail.com> wrote: >> @x = external global %0* > > Hi Rob, > > Try removing the 'extern', as it implies the variable storage is > elsewhere (ie. another object file). >I have to pass something from the LinkageTypes enum to the constructor. I tried others, like GlobalVariable::InternalLinkage, which dumps as "internal global" but the error was the same. Rob
On Wed, Jan 12, 2011 at 11:28 PM, Rob Nikander <rob.nikander at gmail.com> wrote:> I'm trying to define a mutable variable, outside functions. The code > below is trying to evaluate an expression much like "x = 1" at the > module level in Python. It appears that when it tries to JIT the > function there is an error because there is no storage allocated for > 'x'. How do I do that? > > ----- dumped IR ----- > ; ModuleID = 'repl-module' > > %0 = type opaque > > @x = external global %0*First, replace %0* with a concrete type (like the i8* in your later post). Then give @x an initializer. 'undef' is good enough if you don't want to assign an actual value yet. This should turn it into a definition instead of a declaration.
On Thu, Jan 13, 2011 at 2:34 AM, Frits van Bommel <fvbommel at gmail.com> wrote:> On Wed, Jan 12, 2011 at 11:28 PM, Rob Nikander <rob.nikander at gmail.com> wrote: > > First, replace %0* with a concrete type (like the i8* in your later post). > Then give @x an initializer. 'undef' is good enough if you don't want > to assign an actual value yet. This should turn it into a definition > instead of a declaration.Thanks, the initializer did it. Using opaque* works, at least in this case; but I've replaced it with i8*. Rob
Apparently Analagous Threads
- [LLVMdev] How to define a global variable?
- [LLVMdev] How to define a global variable?
- Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
- Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
- [LLVMdev] How to define a global variable?