Skip to content

InitializeStaticGlobals: don't merge stores for structs with unreferencable storage #72183

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
Mar 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ private func getSequenceOfElementStores(firstStore: StoreInst) -> ([StoreInst],
return nil
}
let structAddr = elementAddr.struct
if structAddr.type.isMoveOnly {
let structType = structAddr.type
if structType.isMoveOnly {
return nil
}
guard let fields = structAddr.type.getNominalFields(in: firstStore.parentFunction) else {
if structType.nominal.isStructWithUnreferenceableStorage {
return nil
}
guard let fields = structType.getNominalFields(in: firstStore.parentFunction) else {
return nil
}
let numElements = fields.count
Expand Down
5 changes: 5 additions & 0 deletions test/SILOptimizer/Inputs/bitfield.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

struct S {
int a;
int b : 8;
};
5 changes: 4 additions & 1 deletion test/SILOptimizer/global_init_opt.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -parse-as-library -O -module-name=test %s -emit-sil | %FileCheck %s
// RUN: %target-swift-frontend -parse-as-library -O -import-objc-header %S/Inputs/bitfield.h -module-name=test %s -emit-sil | %FileCheck %s

// REQUIRES: swift_in_compiler

Expand All @@ -7,6 +7,9 @@ var gg: Int = {
return 27
}()

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

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