-2

I'm new to LLVM, does LLVM IR has scope for duplicated variable name ?

For example:


@x = global i32 0


define void @hello() {
  %x = alloca i32, align 4
}

Does @x variable name duplicates with %x ?

linrongbin
  • 2,967
  • 6
  • 31
  • 59

1 Answers1

2

Had you try to write a code that do something with these variables, you'd find that the answer is NO.

To access @x you'll have to use Module::GetGlobalVariable method, which obviously wouldn't pick up %x. Similarly, to access %x, you'd have to iterate a Functions BasicBlocks, looking for an Instruction named "x". Yes, the %x thing is not a variable, but an instruction.

Finally, at the textual IR level these values also can't be mixed in any way, because global values in LLVM are prefixed with @ while local ones - with %.

arrowd
  • 33,231
  • 8
  • 79
  • 110