mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
5945030af1
If we encounter an error prior to 'initialize-static-globals', this pass will not run, and will not convert globals to be statically-initialized at all, regardless of whether or not it would have been possible. This means that diagnostics on failure to do so would then always be emitted, likely as false-positives. Avoid emitting these diagnostics in a context that contains a prior error. As a future alternative, we could refine the conditions that make `initialize-static-globals` give up on a given function/value, but for now we need to ensure we do not emit spurious diagnostics. Resolves rdar://172195372
23 lines
835 B
Swift
23 lines
835 B
Swift
// Constant globals should "work" even when used across files in non-WMO builds.
|
|
// REQUIRES: swift_feature_CompileTimeValues
|
|
// REQUIRES: swift_feature_CompileTimeValuesPreview
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
|
|
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -parse-as-library -enable-experimental-feature CompileTimeValues -enable-experimental-feature CompileTimeValuesPreview
|
|
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -verify -enable-experimental-feature CompileTimeValues -enable-experimental-feature CompileTimeValuesPreview
|
|
|
|
//--- MyModule.swift
|
|
|
|
public func foo() -> Int {
|
|
return 42
|
|
}
|
|
|
|
//--- Main.swift
|
|
|
|
import MyModule
|
|
|
|
@const let constGlobal1: Int = foo()
|
|
// expected-error@-1 {{'@const' value should be initialized with a compile-time value}}
|
|
|