Skip to content

Commit 2ab0452

Browse files
committed
InitializeStaticGlobals: allow statically initialized globals of non-loadable types
1 parent 201bb44 commit 2ab0452

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ class SILBuilder {
16791679
StructInst *createStruct(SILLocation Loc, SILType Ty,
16801680
ArrayRef<SILValue> Elements,
16811681
ValueOwnershipKind forwardingOwnershipKind) {
1682-
ASSERT(isLoadableOrOpaque(Ty));
1682+
ASSERT(isLoadableOrOpaque(Ty) || isInsertingIntoGlobal());
16831683
return insert(StructInst::create(getSILDebugLocation(Loc), Ty, Elements,
16841684
getModule(), forwardingOwnershipKind));
16851685
}
@@ -1724,7 +1724,8 @@ class SILBuilder {
17241724
EnumInst *createEnum(SILLocation Loc, SILValue Operand,
17251725
EnumElementDecl *Element, SILType Ty,
17261726
ValueOwnershipKind forwardingOwnershipKind) {
1727-
ASSERT(isLoadableOrOpaque(Ty));
1727+
ASSERT(isLoadableOrOpaque(Ty) ||
1728+
(isInsertingIntoGlobal() && getTypeLowering(Ty).isFixedABI()));
17281729
// Assert that this works and does not crash.
17291730
(void)getModule().getCaseIndex(Element);
17301731

lib/SIL/Utils/SILBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ bool BridgedGlobalVar::canBeInitializedStatically() const {
356356
auto props = global->getModule().Types.getTypeProperties(
357357
global->getLoweredType(),
358358
TypeExpansionContext::noOpaqueTypeArchetypesSubstitution(expansion));
359-
return props.isLoadable();
359+
return props.isFixedABI();
360360
}
361361

362362
bool BridgedGlobalVar::mustBeInitializedStatically() const {

0 commit comments

Comments
 (0)