Forward references of globals in .ll files

I’m experiencing a weird issue during .ll file parsing, and I’m not sure if it’s a bug in the .ll parser, or if I’m just not understanding the IR.

Take the following IR:

@a = addrspace(1) global i8 0
@a2 = global i8 addrspace(1)* @a

This parses fine. But if I rearrange the statements to:

@a2 = global i8 addrspace(1)* @a
@a = addrspace(1) global i8 0

then I get an ugly assertion failure:

Assertion failed: (InitVal->getType() == getType()->getElementType() && “Initializer type must match GlobalVariable type”), function setInitializer, file /Users/jholewinski/projects/llvm/src/llvm/lib/VMCore/Globals.cpp, line 168.

Looking at the debugger, I see that InitVal (the initializer for @a2) has type i8*, which looks incorrect as it drops the addrspace from the definition of @a.

Before I go too far into this, should this IR work? It looks like the parser is failing to properly process the forward declaration of @a, but I just want to be sure.

Looks like it should work.

-Eli

Does not work and same error even on old r157485 build.

- D.

Yes, and that's a bug.

-Eli

If no one else is looking at this, I’ll take a stab at it next week sometime.