mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Lazy emission of SIL global variables caused us to go through the creation of two different LLVM struct types for the same initialization, tripping an assertion in LLVM. Cache it along with other information about the static-initialized object rather than rebuilding it. Also fix the lazy_globals test to account for the laziness, generalizing it to also run on arm64 so I won't miss it locally.
42 lines
1.6 KiB
Swift
42 lines
1.6 KiB
Swift
// RUN: %target-swift-frontend -parse-as-library -emit-ir -primary-file %s | %FileCheck %s
|
|
|
|
// REQUIRES: CPU=x86_64 || CPU=arm64
|
|
|
|
// CHECK: @"$s12lazy_globals1xSivp" = hidden global %TSi zeroinitializer, align 8
|
|
// CHECK: @"$s12lazy_globals1ySivp" = hidden global %TSi zeroinitializer, align 8
|
|
// CHECK: @"$s12lazy_globals1zSivp" = hidden global %TSi zeroinitializer, align 8
|
|
// CHECK: @"[[T:.*]]Wz" = internal global i64 0, align 8
|
|
|
|
// CHECK: define internal void @"[[T]]WZ"(ptr %0) {{.*}} {
|
|
// CHECK: entry:
|
|
// CHECK: store i64 1, ptr @"$s12lazy_globals1xSivp", align 8
|
|
// CHECK: store i64 2, ptr @"$s12lazy_globals1ySivp", align 8
|
|
// CHECK: store i64 3, ptr @"$s12lazy_globals1zSivp", align 8
|
|
// CHECK: ret void
|
|
// CHECK: }
|
|
|
|
// CHECK: define hidden swiftcc ptr @"$s12lazy_globals1xSivau"() {{.*}} {
|
|
// CHECK: entry:
|
|
// CHECK: call void @swift_once(ptr @"[[T]]Wz", ptr @"[[T]]WZ", ptr undef)
|
|
// CHECK: }
|
|
|
|
// CHECK: define hidden swiftcc ptr @"$s12lazy_globals1ySivau"() {{.*}} {
|
|
// CHECK: entry:
|
|
// CHECK: call void @swift_once(ptr @"[[T]]Wz", ptr @"[[T]]WZ", ptr undef)
|
|
// CHECK: }
|
|
|
|
// CHECK: define hidden swiftcc ptr @"$s12lazy_globals1zSivau"() {{.*}} {
|
|
// CHECK: entry:
|
|
// CHECK: call void @swift_once(ptr @"[[T]]Wz", ptr @"[[T]]WZ", ptr undef)
|
|
// CHECK: }
|
|
var (x, y, z) = (1, 2, 3)
|
|
|
|
// CHECK: define hidden swiftcc i64 @"$s12lazy_globals4getXSiyF"() {{.*}} {
|
|
// CHECK: entry:
|
|
// CHECK: %0 = call swiftcc ptr @"$s12lazy_globals1xSivau"()
|
|
// CHECK: %._value = getelementptr inbounds{{.*}} %TSi, ptr %0, i32 0, i32 0
|
|
// CHECK: [[V:%.*]] = load i64, ptr %._value, align 8
|
|
// CHECK: ret i64 [[V]]
|
|
// CHECK: }
|
|
func getX() -> Int { return x }
|