[all-commits] [llvm/llvm-project] 549773: [Dwarf] Reference the correct CU when inlining

Ellis Hoag via All-commits all-commits at lists.llvm.org
Wed Oct 5 09:19:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 549773f9e98f9c5895f4cc461a7fb1dbdb216af8
      https://github.com/llvm/llvm-project/commit/549773f9e98f9c5895f4cc461a7fb1dbdb216af8
  Author: Ellis Hoag <ellis.sparky.hoag at gmail.com>
  Date:   2022-10-05 (Wed, 05 Oct 2022)

  Changed paths:
    M llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    M llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
    A llvm/test/DebugInfo/Generic/cross-cu-inlining-2.ll

  Log Message:
  -----------
  [Dwarf] Reference the correct CU when inlining

Sometimes when a function is inlined into a different CU, `llvm-dwarfdump --verify` would find an inlined subroutine with an invalid abstract origin. This is because `DwarfUnit::addDIEEntry()` will incorrectly assume the inlined subroutine and the abstract origin are from the same CU if it can't find the CU for the inlined subroutine.

In the added test, the inlined subroutine for `bar()` is created before the CU for `B.swift` is created, so it tries to point to `goo()` in the wrong CU. Interestingly, if we swap the order of the two functions then we don't see a crash since the module for `goo()` is created first.

The fix is to give a parent DIE to `ScopeDIE` before calling `addDIEEntry()` so that its CU can be found. Luckily, `constructInlinedScopeDIE()` is only called once so we can pass it the DIE of the scope's parent and give it a child just after it's created.

`constructInlinedScopeDIE()` should always return a DIE, so assert that it is not null.

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D135114




More information about the All-commits mailing list