swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.6k stars 10.37k forks source link

[debuginfo][windows, PDB] windows debug info drops line location of inlined trap from array's subscript #75911

Open hyp opened 3 months ago

hyp commented 3 months ago

Description

An array subscript getter out-of-bounds trap has an invalid line location in the LLVM debug information, leading to a wrong line location in the crash. This is for PDB for windows.

Reproduction

import FoundationXML
import Foundation

public struct AppInstaller: Equatable {

    public init(with root: XMLElement) throws {
        let element = root.elements(forName: "MainPackage")[0]
    }

}

build with

> swiftc -c test.swift -S -emit-ir  -g -debug-info-format=codeview -o test.ir -O

you can see that the llvm.trap instruction has a debug location with line entry 0, which isn't preserved in PDB.

Expected behavior

The original location should be preserved without a zero line.

Environment

swift --version Swift version 6.0-dev (LLVM 73a346c9caf32cc, Swift e2ad12ba5c3bc2a) Target: x86_64-unknown-windows-msvc

Additional information

No response

adrian-prantl commented 3 months ago

Can you post the -g -emit-sil and the -emit-ir ouptut for the function?

adrian-prantl commented 3 months ago

Can I even build this on a non-windows machine?