Inline Transformation and Dwarf Debugging Information"

Inline transformation has been applied to functions one, second, and third. However, in the Dwarf debugging information, these functions are not associated with the “inline” tag (DW_TAG_inlined_subroutine). Is there any guidance to understand this, or could it be a bug?

#include <stdio.h>

void third(int arg3){
  int var3 = arg3;
  int* a = 0;
  a[0] = var3;
}

void second(int arg2){
  int var2 = arg2;
  third(var2+1);
}

void first(int arg1){
  int var1 = arg1;
  second(var1+1);
}

int main(){
  int some_int = 1;
  first(some_int);
  return 0;
}

Maybe @ZequanWu can take a look

Do you have a command line to repro this? Did you also verify that all 3 functions get inlined by disassembling?

I see that third has undefined behavior; a[0] dereferences the pointer a which was initialized to 0. So, any inlined instances would be optimized away entirely, and therefore there won’t be any DW_TAG_inlined_subroutine entries.

You will still get DW_TAG_subprogram entries because all those functions are visible externally, and therefore have definitions. But you’ll notice that DW_AT_high_pc is 0, meaning the first function has no instructions in it (because of the undefined behavior).

Removing the undefined behavior will help; although these functions all have no externally visible effects, so probably they would still all be optimized away entirely.

clang -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O3 -g prog.c

Not sure if I am correct. why debug info could not handle the issue or just throw an error when parsing it?

I believe the debug info is describing the object file in a reasonable way. The first function has no content, so there are no inlined instances to describe.

There is no “parsing” here. The front end attaches debug-info metadata to each function, and hands off the IR to the optimizer. The optimizer does inlining, which creates inlined references to the inlined functions metadata. The optimizer determines that there is undefined behavior, optimizes away essentially everything, including the inlined references to metadata. When the remaining metadata is turned into DWARF, no inlined_subroutines are generated because there are none left in the metadata.

2 Likes