Skip to content

Inlined subroutine with loop misses part of PC range in debug info #156700

@jryans

Description

@jryans

When the following is compiled...

#include <stdlib.h>
#include <string.h>

struct cmd_struct {
	const char *cmd;
};

extern struct cmd_struct commands[];

static struct cmd_struct *get_builtin(const char *s) {
  int i;
  for (i = 0; i < 20; i++) {
    struct cmd_struct *p = commands + i;
    if (!strcmp(s, p->cmd))
      return p;
  }
  return NULL;
}

void handle_builtin(int argc, const char **argv) {
  struct cmd_struct *builtin;
  builtin = get_builtin(argv[0]);
  if (builtin)
    exit(1);
}

...using Clang 20 at -O1, we see that get_builtin is inlined into handle_builtin, but the debug info for the inlined instance of get_builtin misses an instruction from it's PC range:

Disassembly
0x00000096:     DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin	(0x00000027 "get_builtin")
                  DW_AT_low_pc	(0x0000000000000023)
                  DW_AT_high_pc	(0x0000000000000048)
                  DW_AT_call_file	("/app/example.c")
                  DW_AT_call_line	(22)
                  DW_AT_call_column	(13)

The mov instruction at 0x20 is part of the loop within get_builtin, but for some reason, it is not part of the PC range in the debug info (DW_AT_low_pc says 0x23 instead of 0x20).

Example available on Compiler Explorer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions