Skip to content

Commit 32f3a1d

Browse files
committed
IRGen: remove a wrong assert for global variable initialization
The assert was wrong because in case a global variable reference another global variable, it can be the case that the other variable is first generated as declaration and then "converted" to a definition by adding the constant initializer. rdar://117189962
1 parent 040224e commit 32f3a1d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,11 +2700,6 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var,
27002700
if (gvar) {
27012701
if (forDefinition) {
27022702
updateLinkageForDefinition(*this, gvar, entity);
2703-
2704-
if (var->getStaticInitializerValue()) {
2705-
assert(gvar->hasInitializer() &&
2706-
"global variable referenced before created");
2707-
}
27082703
}
27092704
if (forDefinition && !gvar->hasInitializer())
27102705
initVal = getGlobalInitValue(var, storageType, fixedAlignment);

test/IRGen/referenced_global.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -emit-ir -o - | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
5+
// Check that IRGen doesn't crash when a global variable reference another private global.
6+
7+
// CHECK-LABEL: @"$s17referenced_global1bSPySiGvp" ={{.*}} global {{.*}} ptr @"$s17referenced_global1x{{.*}}"
8+
public var b = UnsafePointer(&x)
9+
private var x = 1

0 commit comments

Comments
 (0)