Skip to content

SIL: let Type.getNominalFields return nil for a struct with unreferenceable storage #82140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SwiftCompilerSources/Sources/SIL/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public struct Type : TypeProperties, CustomStringConvertible, NoReflectionChildr
guard let nominal = nominal, !nominal.isResilient(in: function) else {
return nil
}
if let structDecl = nominal as? StructDecl, structDecl.hasUnreferenceableStorage {
return nil
}
return NominalFieldsArray(type: self, function: function)
}

Expand Down
7 changes: 7 additions & 0 deletions test/SILOptimizer/Inputs/bitfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ struct S {
int a;
int b : 8;
};

struct S2 {
int a;
int :4;
int b;
};

1 change: 1 addition & 0 deletions test/SILOptimizer/global_init_opt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var gg: Int = {

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

// CHECK-LABEL: sil @$s4test3cseSiyF
// CHECK: builtin "once"
Expand Down