Skip to content

Swift produces invalid debug IR #74583

Closed
@ellishg

Description

@ellishg

Description

Swift produces invalid debug info in IR when a block is passed to an ObjC initializer. The output IR fails the verify pass.

Reproduction

main.swift

class C {
  init() {
    let _ = Foo(a:{})
  }
}

objc.h

@interface Foo
- (instancetype)initWithA:(void (*)())a;
@end
$ swiftc main.swift -import-objc-header objc.h -g -emit-ir -o main.ll
$ opt -passes=verify -disable-output main.ll
definition subprograms cannot be nested within DICompositeType when enabling ODR
!74 = distinct !DISubprogram(linkageName: "$s4main1CCACycfcyycfU_", scope: !53, file: !15, line: 3, type: !75, scopeLine: 3, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !14, retainedNodes: !48)
!15 = !DIFile(filename: "main.swift", directory: ".")
!53 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", scope: !18, file: !15, size: 64, elements: !48, runtimeLang: DW_LANG_Swift, identifier: "$s4main1CCD")
!15 = !DIFile(filename: "main.swift", directory: ".")
definition subprograms cannot be nested within DICompositeType when enabling ODR
!79 = distinct !DISubprogram(linkageName: "$s4main1CCACycfcyycfU_To", scope: !53, file: !51, type: !75, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !14, retainedNodes: !48)
!51 = !DIFile(filename: "<compiler-generated>", directory: "")
!53 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", scope: !18, file: !15, size: 64, elements: !48, runtimeLang: DW_LANG_Swift, identifier: "$s4main1CCD")
!15 = !DIFile(filename: "main.swift", directory: ".")
warning: ignoring invalid debug info in main.ll

Expected behavior

Swift should produce IR that does not fail verification.

Environment

$ swift --version
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

The code above does not fail with -gline-tables-only.

The verification fails here, but I've added some code to dump more IR for debugging.
https://github.com/llvm/llvm-project/blob/99f5fcb0d1e04125daa404ff14c9cd14b7a2c40b/llvm/lib/IR/Verifier.cpp#L1499-L1504

This code was added in the apple branch here
swiftlang/llvm-project@1e608f9

and was added upstream here
llvm/llvm-project@2ee4d03

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdebug infoArea → compiler → IRGen: Debug information emission

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions