Skip to content

Commit f279257

Browse files
committed
[cxx-interop] use raw pointer metadata for dynamic FRT field metadata
rdar://117494091
1 parent e7603eb commit f279257

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,8 +3735,7 @@ namespace {
37353735
llvm_unreachable("classes shouldn't have this kind of refcounting");
37363736
case ReferenceCounting::None:
37373737
case ReferenceCounting::Custom:
3738-
llvm_unreachable(
3739-
"Foreign reference types don't conform to 'AnyClass'.");
3738+
return emitFromValueWitnessTable(IGF.IGM.Context.TheRawPointerType);
37403739
}
37413740

37423741
llvm_unreachable("Not a valid ReferenceCounting.");
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
5+
// RUN: %target-build-swift %t/struct.swift -emit-module -emit-library -static -module-name OpaqueStruct -emit-module-path %t/Inputs/OpaqueStruct.swiftmodule -enable-library-evolution
6+
7+
// RUN: %target-swift-emit-irgen %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop -disable-availability-checking | %FileCheck %s
8+
9+
//--- Inputs/module.modulemap
10+
module CxxModule {
11+
header "header.h"
12+
requires cplusplus
13+
}
14+
15+
//--- Inputs/header.h
16+
17+
class
18+
__attribute__((swift_attr("import_reference")))
19+
__attribute__((swift_attr("retain:immortal")))
20+
__attribute__((swift_attr("release:immortal")))
21+
SingletonReference {
22+
public:
23+
SingletonReference(const SingletonReference &) = delete;
24+
25+
void method();
26+
};
27+
28+
class
29+
__attribute__((swift_attr("import_reference")))
30+
__attribute__((swift_attr("retain:retainS")))
31+
__attribute__((swift_attr("release:releaseS")))
32+
SingletonReferenceRef {
33+
public:
34+
SingletonReferenceRef(const SingletonReferenceRef &) = delete;
35+
36+
void method();
37+
};
38+
39+
void retainS(SingletonReferenceRef *);
40+
void releaseS(SingletonReferenceRef *);
41+
42+
//--- struct.swift
43+
44+
public struct ResilientStruct {
45+
let x: Int
46+
}
47+
48+
//--- test.swift
49+
50+
import OpaqueStruct
51+
import CxxModule
52+
53+
public struct ImmortalFRT_OpaqueLayout {
54+
public let y: SingletonReference
55+
public let x: ResilientStruct
56+
}
57+
58+
public struct SharedFRT_OpaqueLayout {
59+
public let x: ResilientStruct
60+
public let y: SingletonReferenceRef
61+
}
62+
63+
// CHECK: define{{.*}} @"$s4test24ImmortalFRT_OpaqueLayoutVMr"
64+
// CHECK: store ptr getelementptr inbounds (ptr, ptr @"$sBpWV", i32
65+
66+
// CHECK: define{{.*}} @"$s4test22SharedFRT_OpaqueLayoutVMr"
67+
// CHECK: store ptr getelementptr inbounds (ptr, ptr @"$sBpWV", i32

0 commit comments

Comments
 (0)