[IRGen] Correctly assign lazily-emitted global variables in multi-threaded IRGen

With multi-threaded IRGen, the global variables associated with "once"
initialization tokens were not getting colocated with their actual
global variables, which caused the initialization code to get split
across different files. This issue manifest as autolinking errors in
some projects.

Fixes rdar://162400654.
This commit is contained in:
Doug Gregor
2025-11-10 23:08:57 -08:00
parent f606979c5f
commit bce3fa000b
6 changed files with 63 additions and 13 deletions

View File

@@ -0,0 +1,24 @@
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src
// RUN: %target-swift-frontend %t/src/A.swift %t/src/B.swift -emit-ir -o %t/A.ll -o %t/B.ll -num-threads 2 -O -g -module-name test
// RUN: %FileCheck --check-prefix=CHECK-A %s <%t/A.ll
// RUN: %FileCheck --check-prefix=CHECK-B %s <%t/B.ll
//--- A.swift
public func f() -> String { "hello" }
public func g() -> Bool {
f() == X.introduction
}
// CHECK-A: @"$s4test1XV12introduction_Wz" = external hidden global
//--- B.swift
public struct X {
public static var introduction: String = f().uppercased()
}
// CHECK-B: @"$s4test1XV12introduction_Wz" = weak_odr hidden global