Skip to content

Commit 48ebd52

Browse files
authored
Merge pull request #82140 from eeckstein/fix-init-static-globals
SIL: let `Type.getNominalFields` return nil for a struct with unreferenceable storage
2 parents ba715db + 8d73f88 commit 48ebd52

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
159159
guard let nominal = nominal, !nominal.isResilient(in: function) else {
160160
return nil
161161
}
162+
if let structDecl = nominal as? StructDecl, structDecl.hasUnreferenceableStorage {
163+
return nil
164+
}
162165
return NominalFieldsArray(type: self, function: function)
163166
}
164167

test/SILOptimizer/Inputs/bitfield.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ struct S {
33
int a;
44
int b : 8;
55
};
6+
7+
struct S2 {
8+
int a;
9+
int :4;
10+
int b;
11+
};
12+

test/SILOptimizer/global_init_opt.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var gg: Int = {
99

1010
// Test that the compiler doesn't crash with a global C bitfield.
1111
var bitfield = S(a: 0, b: 0)
12+
var bitfield2 = S2(a: 0, b: 0)
1213

1314
// CHECK-LABEL: sil @$s4test3cseSiyF
1415
// CHECK: builtin "once"

0 commit comments

Comments
 (0)