File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -3282,8 +3282,8 @@ llvm::Function *IRGenModule::getAddrOfSILFunction(
32823282 //
32833283 // FIXME: We should be able to set the linkage unconditionally here but
32843284 // some fixes are needed for Cxx interop.
3285- if (auto *DC = f->getDeclContext ())
3286- if (getSwiftModule ()->isImportedAsWeakLinked (DC-> getParentModule () ))
3285+ if (auto *parentModule = f->getParentModule ())
3286+ if (getSwiftModule ()->isImportedAsWeakLinked (parentModule ))
32873287 fn->setLinkage (link.getLinkage ());
32883288 }
32893289
Original file line number Diff line number Diff line change 1+ // RUN: %empty-directory(%t)
2+ // RUN: %build-irgen-test-overlays
3+ // RUN: split-file %s %t
4+
5+ // RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-module -emit-module-path %t/Intermediate.swiftmodule -parse-as-library %t/Intermediate.swift -enable-library-evolution
6+ //
7+ // RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -primary-file %t/Client.swift -emit-ir | %FileCheck %s
8+
9+ // REQUIRES: objc_interop
10+
11+ //--- Intermediate.swift
12+
13+ import Foundation
14+
15+ public func hasDefaultArgument( _ n: NSNotification = NSNotification ( ) ) { }
16+
17+ @_alwaysEmitIntoClient
18+ public func aeicFuncUsingWeakVar( ) {
19+ _ = weak_variable
20+ }
21+
22+ @_alwaysEmitIntoClient
23+ public func aeicFuncUsingStrongVar( ) {
24+ _ = strong_variable
25+ }
26+
27+ @_alwaysEmitIntoClient
28+ public func aeicFuncCallingAlwaysAvailableFunc( ) {
29+ always_available_function ( )
30+ }
31+
32+
33+ //--- Client.swift
34+
35+ import Intermediate
36+ @_weakLinked import Foundation
37+
38+ // Symbols from `Foundation` should have weak linkage even when the references
39+ // to them are inlined from `Intermediate`, which imported `Foundation` without
40+ // `@_weakLinked`.
41+
42+ func testDefaultArguments( ) {
43+ // CHECK-DAG: @"OBJC_CLASS_$_NSNotification" = extern_weak global %objc_class
44+ hasDefaultArgument ( )
45+ }
46+
47+ func testAlwaysEmitIntoClient( ) {
48+ // CHECK-DAG: @weak_variable = extern_weak global
49+ aeicFuncUsingWeakVar ( )
50+
51+ // CHECK-DAG: @strong_variable = extern_weak global
52+ aeicFuncUsingStrongVar ( )
53+
54+ // CHECK-DAG: declare extern_weak void @always_available_function()
55+ aeicFuncCallingAlwaysAvailableFunc ( )
56+ }
You can’t perform that action at this time.
0 commit comments