[DebugInfo] Fix potential CU mismatch for attachRangesOrLowHighPC
authorDianQK <dianqk@dianqk.net>
Sat, 22 Oct 2022 12:39:21 +0000 (20:39 +0800)
committerDianQK <dianqk@dianqk.net>
Sat, 22 Oct 2022 13:22:01 +0000 (21:22 +0800)
commitd20e4a1d68aa8e14c4e524e4d4eeb4445acac401
treec7c8bc2edaf81c818ca638767aaf37dec185506a
parentfc26a75280c51e925a3b5df56b3f47af45a3cac2
[DebugInfo] Fix potential CU mismatch for attachRangesOrLowHighPC

When a CU attaches some ranges for a subprogram or an inlined code, the CU should be that of the subprogram/inlined code that was emitted.
If not, then these emitted ranges will use the incorrect base of the CU in `emitRangeList`.

A reproducible example is:
When linking these two LLVM IRs,  dsymutil will report no mapping for range or inconsistent range data warnings.

`foo.swift`
```swift
import AppKit.NSLayoutConstraint

public class Foo {

    public var c: Int {
        get {
            Int(NSLayoutConstraint().constant)
        }
        set {
        }
    }

}
```

`main.swift`
```swift
// no mapping for range
let f: Foo! = nil
// inconsistent range data
//let l: Foo = Foo()
```

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D136039
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
llvm/test/DebugInfo/Generic/cross-cu-inlining-ranges.ll [new file with mode: 0644]