[DebugInfo] Fix handling of @_originallyDefinedIn types

Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
This commit is contained in:
Augusto Noronha
2024-11-22 08:00:56 +00:00
parent 55009bf718
commit 72b0120b43
9 changed files with 232 additions and 58 deletions

View File

@@ -1,2 +1,22 @@
@available(macOS 10, *)
@_originallyDefinedIn(module: "Barn", macOS 10.1) public struct Horse {}
@_originallyDefinedIn(
module: "Barn", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public struct Horse {
public init() {}
}
@_originallyDefinedIn(
module: "Barn", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public class Cow {
public init() {}
}
@_originallyDefinedIn(
module: "Barn", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public class Sheep {
public init() {}
}

View File

@@ -1,9 +1,14 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/local_type_originally_defined_in_other.swiftmodule %S/Inputs/local_type_originally_defined_in_other.swift
// RUN: %target-swift-frontend -I%t -g -emit-ir %s
// RUN: %target-swift-frontend -I%t -g -emit-ir %s -o - | %FileCheck %s
// REQUIRES: OS=macosx
import local_type_originally_defined_in_other
public func definedInOtherModule() {
let s = Sheep()
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "Sheep"{{.*}}identifier: "$s4Barn5SheepCD
}
public func localTypeAliasTest(horse: Horse) {
// The local type mangling for 'A' mentions 'Horse', which must
// be mangled using it's current module name, and not the
@@ -13,4 +18,21 @@ public func localTypeAliasTest(horse: Horse) {
let info = UnsafeMutablePointer<A>.allocate(capacity: 1)
_ = info
}
// CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest5horsey4Barn5HorseV_tF1AL_aD"
}
public func localTypeAliasTest() -> Horse {
typealias B = Int
let info = UnsafeMutablePointer<B>.allocate(capacity: 1)
_ = info
return Horse()
// CHECK: DIDerivedType(tag: DW_TAG_typedef, name: "$s32local_type_originally_defined_in0A13TypeAliasTest4Barn5HorseVyF1BL_aD"
}
public func localTypeAliasTestGeneric<T: Cow>(cow: T) {
typealias C = Int
let info = UnsafeMutablePointer<C>.allocate(capacity: 1)
_ = info
}

View File

@@ -3,11 +3,5 @@
class SomeClass {}
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "SomeClass",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye9SomeClassCD"
@available(macOS 10.13, *)
@_originallyDefinedIn(module: "ThirdModule", OSX 10.12)
class DefinedElsewhere {}
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "DefinedElsewhere",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye16DefinedElsewhereCD")
let v1 = SomeClass()
let v2 = DefinedElsewhere()

View File

@@ -0,0 +1,11 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -module-name=Hello -module-abi-name Goodbye -emit-ir -o - | %FileCheck %s
// REQUIRES: OS=macosx
//
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
@_originallyDefinedIn(
module: "ThirdModule", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
public class DefinedElsewhere {}
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "DefinedElsewhere",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s11ThirdModule16DefinedElsewhereCD")
let v2 = DefinedElsewhere()

View File

@@ -1,14 +1,41 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o - | %FileCheck %s
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o -
@_originallyDefinedIn(
module: "Other", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public struct A {
let i = 10
}
// REQUIRES: OS=macosx
//
@_originallyDefinedIn(
module: "Other", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public struct A {
let i = 10
}
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A",{{.*}}identifier: "$s21originally_defined_in1AVD",{{.*}}specification: ![[S1:[0-9]+]]
// CHECK: [[S1]] = !DICompositeType(tag: DW_TAG_structure_type, name: "A", scope: ![[S2:[0-9]+]]
// CHECK: [[S2]] = !DIModule({{.*}}name: "Other"
@_originallyDefinedIn(
module: "Other", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
public struct B {
let i = 10
}
// Test that a type with an invalid @_originallyDefinedIn does not change the mangled name.
@_originallyDefinedIn(
module: "Other", iOS 2.0, macOS 2.0, tvOS 2.0, watchOS 2.0)
@available(iOS 1.0, macOS 1.0, tvOS 1.0, watchOS 1.0, *)
private struct Invalid {
let i = 20
}
// CHECK: ![[MOD:[0-9]+]] = !DIModule(scope: null, name: "originally_defined_in"
//
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A",{{.*}}scope: ![[S:[0-9]+]]{{.*}}identifier: "$s5Other1AVD"
// CHECK: [[S]] = !DIModule({{.*}}name: "Other"
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "Invalid",{{.*}}identifier: "$s21originally_defined_in
// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "$s5Other1AVD",{{.*}}scope: ![[MOD]]
//
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "$s5Other1AV_ACtD",
let a = A()
let b = B.self
let c = (A(), A())
private let i = Invalid()