[LLVMdev] forward declarations of global values

Eli Friedman eli.friedman at gmail.com
Thu Jul 16 17:34:54 PDT 2009


On Thu, Jul 16, 2009 at 4:00 PM, Zoltan Varga<vargaz at gmail.com> wrote:
>   Is it possible to use forward declarations for global variables when
> emitting llvm IL from C++ ? I.e. if I have a global array, but I
> can't determine its size until after the llvm IL code which uses it is
> emitted.

The way clang deals with such constructs is that it emits a
placeholder global for the declaration, then when it sees a definition
that has a different LLVM type, it creates a new global definition,
takes the name of the old global declaration, replaces all the uses of
the old global declaration with a bitcast of the new global
declaration, then erases the old global declaration.

-Eli




More information about the llvm-dev mailing list