Preserve debug info for IPA ICF wrappers
Ensures debug information is correctly attached to function wrappers created by IPA ICF.
This commit resolves an issue where debug information was not correctly attached to function wrappers generated by IPA ICF (Interprocedural Analysis, Identical Code Folding). When ICF replaces a function’s body with a wrapper, the original function’s debug info could be lost. The fix preserves the DECL_IGNORED_P flag across forced GIMPLE thunk expansion, allowing the wrapper’s address to be correctly associated with its corresponding debug subprogram DIE. A new test case verifies this fix.
In Details
In cgraphunit.cc, the cgraph_node::create_wrapper function generates thunk wrappers for functions optimized by IPA ICF. When force_gimple_thunk is set, the declaration's DECL_IGNORED_P flag is temporarily set, which normally prevents final debug emission. For ICF wrappers, this caused the final debug information (DW_TAG_subprogram DIE) to not include the wrapper's address. This change preserves the original DECL_IGNORED_P value, ensuring that if the source declaration was not ignored, its final debug DIE can be updated with the wrapper's address.
- IPA ICF
- Interprocedural Analysis - Identical Code Folding. A compiler optimization that identifies identical functions or code sections across a program and replaces duplicates with a single version, often using wrappers.
- debug info
- Metadata generated by the compiler that allows debuggers to map executable code back to the original source code, enabling features like breakpoints and variable inspection.
- DIE
- Debugging Information Entry. A fundamental unit of DWARF debugging information, representing a program entity like a function, variable, or type.
- DW_TAG_subprogram
- A DWARF tag that represents a function or subroutine in the source code.
- GIMPLE thunk
- A small piece of code generated by the compiler (often for trampoline or wrapper purposes) represented in GCC's intermediate representation called GIMPLE.