GlobalVaraible and Function have the same name

Hi all,

I just walked across an interesting situation in Module::getOrInsertFunction(Name, Type) in the LLVM C API.

In my particular case:

One of the first things we do is add a global variable named foo which is a [ 100 x i64 ].

Later we add a function void foo(...)

unfortunately, when we do the getOrInsertFunction we get back

void (...) * bitcast ([100 x i64]* @foo_ to void (...)*)

because the symbol foo already exists in the ValueSymbolTable.

Am I correct in interpreting this as a constraint that no two items in the ValueSymbolTable
can have the same name, even if they're of entirely different types (in this case Function entry point and
global variable) ? Is there any way, short of renaming on our end, around this? Thanks!

    -Tony S.

Am I correct in interpreting this as a constraint that no two items in
the ValueSymbolTable
can have the same name, even if they're of entirely different types (in
this case Function entry point and
global variable)?

Yes.

Is there any way, short of renaming on our end,
around this? Thanks!

You can use some form of name mangling. This is what C++ compilers do to implement support for overloading.

-Chris

That's correct; LLVM does not support overloading symbols based on type. Neither does the linker, though. If you're implementing a high level language, you may need to implement name mangling.

— Gordon