Skip to content

Commit da5888f

Browse files
committed
[IRGen] Bail on opt when seeing non-ABI field.
When analyzing a struct's layout to determine whether it contains a single non-empty field, bail upon encountering a field that is not ABI accessible. Previously, rather than bailing (though that was the intent), the field was ignored. The result was that struct's with a single non-empty field and any number of ABI inaccessible fields would be treated as if they only had a single non-empty field. Trouble ensued. rdar://79513293
1 parent d00ea98 commit da5888f

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

lib/IRGen/GenRecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class RecordTypeInfo<Impl, Base, FieldImpl,
550550
if (field.isEmpty()) continue;
551551

552552
// If the field is not ABI-accessible, suppress this.
553-
if (!field.isABIAccessible()) continue;
553+
if (!field.isABIAccessible()) return 0;
554554

555555
// If we've already found an index, then there isn't a
556556
// unique non-empty field.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum E<Value> {
2+
case s(Value)
3+
case n
4+
}
5+
6+
public struct S<Value> {
7+
var e: E<Value>
8+
var b: Bool = false
9+
10+
public init() {
11+
self.e = .n
12+
}
13+
}
14+
15+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public struct Unfixed {
2+
var _value: String
3+
var _another: Int
4+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift \
4+
// RUN: -emit-module \
5+
// RUN: %S/Inputs/rdar79513293_Library.swift \
6+
// RUN: -parse-as-library \
7+
// RUN: -module-name Library \
8+
// RUN: -emit-module-path %t/Library.swiftmodule
9+
10+
// RUN: %target-build-swift \
11+
// RUN: -c \
12+
// RUN: %S/Inputs/rdar79513293_Library.swift \
13+
// RUN: -parse-as-library \
14+
// RUN: -module-name Library \
15+
// RUN: -o %t/Library.o
16+
17+
// RUN: %target-build-swift \
18+
// RUN: -emit-module \
19+
// RUN: %S/Inputs/rdar79513293_Resilient.swift \
20+
// RUN: -parse-as-library \
21+
// RUN: -enable-library-evolution \
22+
// RUN: -module-name Resilient \
23+
// RUN: -emit-module-path %t/Resilient.swiftmodule
24+
25+
// RUN: %target-build-swift \
26+
// RUN: -c \
27+
// RUN: %S/Inputs/rdar79513293_Resilient.swift \
28+
// RUN: -parse-as-library \
29+
// RUN: -enable-library-evolution \
30+
// RUN: -module-name Resilient \
31+
// RUN: -o %t/Resilient.o
32+
33+
// RUN: %target-build-swift \
34+
// RUN: -c \
35+
// RUN: %s \
36+
// RUN: -o %t/main.o \
37+
// RUN: -I %t
38+
39+
// RUN: %target-swiftc_driver \
40+
// RUN: %t/Resilient.o \
41+
// RUN: %t/Library.o \
42+
// RUN: %t/main.o \
43+
// RUN: -o %t/main
44+
45+
// RUN: %target-codesign %t/main
46+
// RUN: %target-run %t/main | %FileCheck %s
47+
48+
import Library
49+
import Resilient
50+
51+
protocol P {}
52+
53+
struct I: P {
54+
var s = S<Unfixed?>()
55+
}
56+
57+
func main() {
58+
let ps = [I() as P]
59+
for _ in ps {}
60+
}
61+
62+
main()
63+
print("ok")
64+
// CHECK: ok

0 commit comments

Comments
 (0)