Skip to content

Commit 8ec4264

Browse files
committed
IRGen: Fix IR linkage computation for inlined function references from clang modules imported @_weakLinked.
Part of rdar://98521248
1 parent 40eb142 commit 8ec4264

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

0 commit comments

Comments
 (0)