You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[6.2][cxx-interop] Prevent crash when importing a std::optional of nonescapable
When we tried to create a std::optional of a nonescapable type in Swift, the compiler would run into an assertion failure.
This is because std::optional has an anonymous union where one of its members would be of this nonescapable type.
Turns out that we were not handling anonymous unions with nonescapable members correctly.
Fields of anonymous unions are injected to the parent as IndirectFieldDecl, so we need to handle these indirect fields the same way we handle "normal" fields.
rdar://156704699
using HasAnonUnionNonEscapable =HasAnonUnion<NonEscapable>;
130
+
using HasAnonStructNonEscapable = HasAnonStruct<NonEscapable>;
131
+
using NonEscapableHasAnonUnionNonEscapable =NonEscapableHasAnonUnion<NonEscapable>;
132
+
using NonEscapableOptional = std::optional<NonEscapable>;
133
+
102
134
//--- test.swift
103
135
import Test
104
136
import CxxStdlib
105
137
106
138
// CHECK: error: cannot find type 'Invalid' in scope
107
139
// CHECK: note: escapable record 'Invalid' cannot have non-escapable field 'v'
140
+
// CHECK-NO-LIFETIMES: error: cannot find type 'Invalid' in scope
141
+
// CHECK-NO-LIFETIMES: note: escapable record 'Invalid' cannot have non-escapable field 'v'
108
142
publicfunc importInvalid(_ x:Invalid){
109
143
}
110
144
111
145
// CHECK: error: a function with a ~Escapable result needs a parameter to depend on
112
-
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function cannot return a ~Escapable result
146
+
// CHECK-NO-LIFETIMES: test.swift:13:32: error: a function cannot return a ~Escapable result
113
147
publicfunc noAnnotations()->View{
114
-
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
115
-
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
148
+
// CHECK: nonescapable.h:17:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
149
+
// CHECK-NO-LIFETIMES: nonescapable.h:17:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
116
150
f(nil)
117
-
// CHECK: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
118
-
// CHECK-NO-LIFETIMES: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
151
+
// CHECK: nonescapable.h:21:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
152
+
// CHECK-NO-LIFETIMES: nonescapable.h:21:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
119
153
// No duplicate warning for f2:
120
-
// CHECK-NOT: nonescapable.h:20
154
+
// CHECK-NOT: nonescapable.h:21
121
155
f2(nil,nil)
122
-
// CHECK: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
123
-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
124
-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: error: a function cannot return a ~Escapable result
156
+
// CHECK: nonescapable.h:25:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
157
+
// CHECK-NO-LIFETIMES: nonescapable.h:25:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
158
+
// CHECK-NO-LIFETIMES: nonescapable.h:25:6: error: a function cannot return a ~Escapable result
125
159
g(nil)
126
160
h1(nil)
127
-
// CHECK-NO-LIFETIMES: nonescapable.h:34:21: error: a function cannot return a ~Escapable result
128
-
h2(nil)
129
161
// CHECK-NO-LIFETIMES: nonescapable.h:35:21: error: a function cannot return a ~Escapable result
162
+
h2(nil)
163
+
// CHECK-NO-LIFETIMES: nonescapable.h:36:21: error: a function cannot return a ~Escapable result
130
164
h3(nil)
131
165
i1()
132
-
// CHECK: nonescapable.h:39:39: error: template parameter 'Missing' does not exist
133
-
// CHECK-NO-LIFETIMES: nonescapable.h:39:39: error: template parameter 'Missing' does not exist
166
+
// CHECK: nonescapable.h:40:39: error: template parameter 'Missing' does not exist
167
+
// CHECK-NO-LIFETIMES: nonescapable.h:40:39: error: template parameter 'Missing' does not exist
134
168
i2()
135
-
// CHECK: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
136
-
// CHECK-NO-LIFETIMES: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
169
+
// CHECK: nonescapable.h:46:33: error: template parameter 'S' expected to be a type parameter
170
+
// CHECK-NO-LIFETIMES: nonescapable.h:46:33: error: template parameter 'S' expected to be a type parameter
137
171
j1()
138
-
// CHECK-NO-LIFETIMES: nonescapable.h:63:41: error: a function cannot return a ~Escapable result
139
-
j2()
140
172
// CHECK-NO-LIFETIMES: nonescapable.h:64:41: error: a function cannot return a ~Escapable result
173
+
j2()
174
+
// CHECK-NO-LIFETIMES: nonescapable.h:65:41: error: a function cannot return a ~Escapable result
141
175
j3()
142
176
k1();
143
-
// CHECK-NO-LIFETIMES: nonescapable.h:70:15: error: a function cannot return a ~Escapable result
177
+
// CHECK-NO-LIFETIMES: nonescapable.h:71:15: error: a function cannot return a ~Escapable result
144
178
k2();
145
-
// CHECK-NO-LIFETIMES: nonescapable.h:71:22: error: a function cannot return a ~Escapable result
179
+
// CHECK-NO-LIFETIMES: nonescapable.h:72:22: error: a function cannot return a ~Escapable result
146
180
k3();
147
181
l1();
148
-
// CHECK: nonescapable.h:77:12: error: a function with a ~Escapable result needs a parameter to depend on
149
-
// CHECK-NO-LIFETIMES: nonescapable.h:77:12: error: a function cannot return a ~Escapable result
182
+
// CHECK: nonescapable.h:78:12: error: a function with a ~Escapable result needs a parameter to depend on
183
+
// CHECK-NO-LIFETIMES: nonescapable.h:78:12: error: a function cannot return a ~Escapable result
0 commit comments