Empty variable name?

Hi,
I’m reading bytecode, and I’ve tripped across a semantic question:

What does it mean when a variable has no name?

I’m in gdb, looking at a function (that I believe is a library or builtin?) that allocates local space for a variable that has no name but does have a field (“addr”). Note the alloca instruction assigns to “%.addr”, and subsequent instructions use “%.addr”.

; Function Attrs: convergent noinline nounwind optnone
define dso_local i32 @_ZN2M_2f_EPFvvENS_1XES2_(void ()* %0, %"struct.M_::X"* byval(%"struct.M_::X") align 4 %mx, %"struct.M_::X"* byval(%"struct.M_::X") align 4 %x) #0 !dbg !2276 {
entry:
  %.addr = alloca void ()*, align 8
  store void ()* %0, void ()** %.addr, align 8
  call void @llvm.dbg.declare(metadata void ()** %.addr, metadata !2286, metadata !DIExpression()), !dbg !2287
...

I assume that this is making space on the stack, but I was just hoping that someone could confirm this or tell me what’s really going on…? (Note: these instructions are the only ones that reference %.addr.)

Thanks very much!
Tim

I’m not totally sure to understand your question, in particular when you wrote “a variable has no name”?

When you read LLVM IR and you see %.addr = alloca void ()*, align 8 the %.addr is an SSA value and the “name” .addr here is exclusively for debugging purposes and has no semantic bearing. In production build there would be no name anywhere.
Note also that the . that starts the name is not meaningful, it does not imply that there are “fields” or anything as far as I know.

joker,
Thanks for replying, and forgive my lack of precision: if I knew what I was talking about, I wouldn’t need to post a question. :slight_smile:

This code I’m looking at will have an alloca instruction where the result looks like: %f.addr, as opposed to %.addr, which is what I’m wondering about:

When I have a DebugLoc object for %f.addr, I can call getVariable(), and it will return “f”, but when I call getVariable() on the DebugLoc object for %.addr, I get an empty string.

So the debug information is telling me that I am allocating local memory to a thing that has no name, which only makes sense if it is to a known thing, like the stack itself.

Almost always, at least for my application, ignoring stuff like this is fine, but every once it a while it bites you, and I just wanted to make sure that I wasn’t ignoring something bad/important/meaningful.

Thanks again,
Tim

OK, so for debug information the logic is entirely decoupled from the “name” you see for the IR SSA Value. Instead the information is encoded in metadata, so in your example (intentionally erasing SSA value names which don’t matter):

  %0 = alloca void ()*, align 8
  call void @llvm.dbg.declare(metadata void ()** %0, metadata !2286, metadata !DIExpression()), !dbg !2287

The debugger will be able to access the memory here based on the information encoded in !2286 and !2287. This may provides more info: Source Level Debugging with LLVM — LLVM 12 documentation