[LLVMdev] How to define a global variable?

Frits van Bommel fvbommel at gmail.com
Wed Jan 12 23:34:32 PST 2011


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.




More information about the llvm-dev mailing list