Skip to content

Commit bf224e2

Browse files
committed
Serialization: Add test for more shadowing scenarios in inlinable code
1 parent 18eb4e4 commit bf224e2

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/// Ensure inlined code in swiftmodules picks the right shadowed decl
2+
/// relative to where they were inlined from, no matter if other imported
3+
/// modules define more shadowers at the inlining site.
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: split-file %s %t
7+
// REQUIRES: objc_interop
8+
9+
/// Reference build: Build libs and client for a normal build.
10+
// RUN: %target-swift-frontend -emit-module %t/RootLib.swift -I %t \
11+
// RUN: -emit-module-path %t/RootLib.swiftmodule
12+
// RUN: %target-swift-frontend -emit-module %t/MiddleLib.swift -I %t \
13+
// RUN: -emit-module-path %t/MiddleLib.swiftmodule
14+
// RUN: %target-swift-frontend -emit-module %t/HighLib.swift -I %t \
15+
// RUN: -emit-module-path %t/HighLib.swiftmodule
16+
// RUN: %target-swift-frontend -emit-sil -O %t/Client.swift -I %t > %t/Client.sil
17+
// RUN: %FileCheck %s --input-file=%t/Client.sil
18+
19+
//--- module.modulemap
20+
module RootLib {
21+
header "RootLib.h"
22+
}
23+
module ClangMiddleLib {
24+
header "ClangMiddleLib.h"
25+
}
26+
27+
//--- RootLib.h
28+
#include <stdio.h>
29+
void ShadowedFunc() { // Never picked as it's shadowed by Swift's.
30+
printf("Clang\n");
31+
}
32+
33+
void ShadowedFuncClang();
34+
35+
//--- ClangMiddleLib.h
36+
#include "RootLib.h"
37+
void ShadowedFuncClang();
38+
39+
//--- RootLib.swift
40+
@_exported import RootLib
41+
@_exported import ClangMiddleLib
42+
43+
public func ShadowedFunc() {
44+
print("Swift Root")
45+
}
46+
47+
@inlinable
48+
@inline(__always)
49+
public func userFromRoot() {
50+
ShadowedFunc() // RootLib Swift one
51+
}
52+
53+
@inlinable
54+
@inline(__always)
55+
public func clangUserFromRoot() {
56+
ShadowedFuncClang()
57+
}
58+
59+
//--- MiddleLib.swift
60+
@_exported import RootLib
61+
62+
public func ShadowedFunc() {
63+
print("Swift Middle")
64+
}
65+
66+
@inlinable
67+
@inline(__always)
68+
public func userFromMiddle() {
69+
ShadowedFunc() // MiddleLib one
70+
}
71+
72+
@inlinable
73+
@inline(__always)
74+
public func clangUserFromMiddle() {
75+
ShadowedFuncClang()
76+
}
77+
78+
//--- HighLib.swift
79+
@_exported import MiddleLib
80+
81+
@inlinable
82+
@inline(__always)
83+
public func userFromHigh() {
84+
ShadowedFunc() // MiddleLib one
85+
}
86+
87+
@inlinable
88+
@inline(__always)
89+
public func explicitUserFromHigh() {
90+
RootLib.ShadowedFunc() // MRootLib.iddleLib one
91+
}
92+
93+
@inlinable
94+
@inline(__always)
95+
public func clangUserFromHigh() {
96+
ShadowedFuncClang()
97+
}
98+
99+
//--- Client.swift
100+
import HighLib
101+
import ClangMiddleLib
102+
103+
// RootLib call its own Swift ShadowedFunc.
104+
userFromRoot()
105+
// CHECK: [[ROOT_FUNC:%.*]] = function_ref @$s7RootLib12ShadowedFuncyyF : $@convention(thin) () -> ()
106+
// CHECK: apply [[ROOT_FUNC]]() : $@convention(thin) () -> ()
107+
explicitUserFromHigh()
108+
// CHECK: apply [[ROOT_FUNC]]() : $@convention(thin) () -> ()
109+
// CHECK-NOT: apply [[ROOT_FUNC]]() : $@convention(thin) () -> ()
110+
111+
// MiddleLib and HighLib call the last ShadowedFunc from MiddleLib.
112+
userFromMiddle()
113+
// CHECK: [[MIDDLE_FUNC:%.*]] = function_ref @$s9MiddleLib12ShadowedFuncyyF : $@convention(thin) () -> ()
114+
// CHECK: apply [[MIDDLE_FUNC]]() : $@convention(thin) () -> ()
115+
userFromHigh()
116+
// CHECK: apply [[MIDDLE_FUNC]]() : $@convention(thin) () -> ()
117+
// CHECK-NOT: apply [[MIDDLE_FUNC]]() : $@convention(thin) () -> ()
118+
119+
// All callers of the clang func use the merged one anyway.
120+
clangUserFromRoot()
121+
clangUserFromMiddle()
122+
clangUserFromHigh()
123+
// CHECK: [[CLANG_FUNC:%.*]] = function_ref @ShadowedFuncClang : $@convention(c) () -> ()
124+
// CHECK: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()
125+
// CHECK: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()
126+
// CHECK: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()
127+
// CHECK-NOT: apply [[CLANG_FUNC]]() : $@convention(c) () -> ()

0 commit comments

Comments
 (0)