[llvm] [RFC] Emit dwarf data for signature-changed or new functions (PR #157349)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 27 05:35:38 PDT 2025


yonghong-song wrote:

> > > foo.clone (int a, int b) { foo (1, { a, b }); }
> > 
> > 
> > This will introduce new functions in symbol table. We will have to remove these functions at the end before final emitting the code. Otherwise users will be really confusing about why these new functions. Also, foo(1, {a, b}) may be inlined.
> 
> What do you mean? From my understanding, this is not the _code_ that should be produced in LLVM IR/MIR/assembly. This is just an illustration of how DWARF should look like.
> 
> > We do not introduce any new LLVM IR functions (e.g. mul.clone or "dummy" functions), but from the DWARF's prospective, the original function is "inlined" into the function with modified signature.

Okay, indeed. mul.clone is not actually in IR. Just a conceptual idea from implementation point of view.

I will try to generate the following dwarf:
```
DW_TAG_subprogram
                DW_AT_low_pc	(0x0000000000000000)
                DW_AT_high_pc	(0x0000000000000006)
                DW_AT_frame_base	(DW_OP_reg7 RSP)
                DW_AT_call_all_calls	(true)
                DW_AT_name	("mul")
                ...

              DW_TAG_formal_parameter
                  DW_AT_location	(DW_OP_reg5 RDI)
                  DW_AT_name	("num1")
                  DW_AT_decl_file	("/app/example.cpp")
                  DW_AT_decl_line	(...)
                  DW_AT_type	(0x0000003d "int")

              DW_TAG_inlined_subroutine
                  DW_AT_abstract_origin	(LOC_A "mul")
                  DW_AT_low_pc	(...)
                  DW_AT_high_pc	(...)
                  DW_AT_call_file	("/app/example.cpp")
                  DW_AT_call_line	(...)
                  DW_AT_call_column	(...)

                    DW_TAG_formal_parameter
                            DW_AT_location	(DW_OP_reg5 RDI)
                            DW_AT_abstract_origin	(LOC_B "num1")
                    DW_TAG_formal_parameter
                            DW_AT_location	(DW_OP_reg5 RDI)
                            DW_AT_abstract_origin	(LOC_C "num2")
             NULL
NULL
```
Here, the top DW_TAG_subprogram will have *final* function types instead of the original one. The original one will be encoded in DW_TAG_inlined_subroutine.

https://github.com/llvm/llvm-project/pull/157349


More information about the llvm-commits mailing list