mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Embedded Swift ends up rewriting the linkage of global variables as part of linking together all of the Swift modules. Doing so for extern global variables (e.g., ones meant to be implemented in C) breaks the LLVM module, because they will never have definitions. Only make this change when the global variable is a definition.
39 lines
873 B
Swift
39 lines
873 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %{python} %utils/split_file.py -o %t %s
|
|
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Extern -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
|
|
// RUN: %target-swift-frontend -enable-experimental-feature Extern -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: swift_feature_Embedded
|
|
// REQUIRES: swift_feature_Extern
|
|
|
|
// BEGIN MyModule.swift
|
|
|
|
@_extern(c)
|
|
func some_c_api()
|
|
|
|
@_transparent
|
|
public func publicFuncInAModule() {
|
|
internalFuncInAModule()
|
|
}
|
|
|
|
@usableFromInline
|
|
internal func internalFuncInAModule() {
|
|
some_c_api()
|
|
_ = globalVariable
|
|
}
|
|
|
|
@_extern(c)
|
|
var globalVariable: Int
|
|
|
|
// BEGIN Main.swift
|
|
|
|
import MyModule
|
|
|
|
@_extern(c)
|
|
func some_c_api()
|
|
|
|
some_c_api()
|
|
publicFuncInAModule()
|