Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,11 +2191,18 @@ void IRGenModule::emitVTableStubs() {

if (!stub) {
// Create a single stub function which calls swift_deletedMethodError().
// Use linkonce_odr hidden to merge these symbols, except on
// COFF where the linker cannot merge them.
bool canLinkOnce = !Module.getTargetTriple().isOSBinFormatCOFF();
auto linkage = canLinkOnce ? llvm::GlobalValue::LinkOnceODRLinkage
: llvm::GlobalValue::InternalLinkage;
stub = llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
llvm::GlobalValue::InternalLinkage,
"_swift_dead_method_stub");
linkage, "_swift_dead_method_stub",
&Module);
ApplyIRLinkage(canLinkOnce ? IRLinkage::InternalLinkOnceODR
: IRLinkage::Internal)
.to(stub);
stub->setAttributes(constructInitialAttributes());
Module.getFunctionList().push_back(stub);
stub->setCallingConv(DefaultCC);
auto *entry = llvm::BasicBlock::Create(getLLVMContext(), "entry", stub);
auto *errorFunc = getDeletedMethodErrorFn();
Expand Down
12 changes: 8 additions & 4 deletions test/IRGen/static-vtable-stubs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@

// REQUIRES: concurrency

// Note: Windows uses internal linkage, which puts an extra step symbol before
// _swift_dead_method_stub.
// UNSUPPORTED: OS=windows-msvc

//--- A.swift
open class C {
private var i: [ObjectIdentifier:Any] = [:]

private func foo() async {}
}

// CHECK: @"$s1M1CC3foo33_{{.*}}Tu" = hidden global %swift.async_func_pointer <{ {{.*}} @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
// CHECK: @"$s1M1CC3foo33_{{.*}}Tu" = hidden global %swift.async_func_pointer <{ {{.*}} @_swift_dead_method_stub

// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvs" = hidden alias void (), ptr @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvM" = hidden alias void (), ptr @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvs" = hidden alias void (), ptr @_swift_dead_method_stub
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvM" = hidden alias void (), ptr @_swift_dead_method_stub

// CHECK: define hidden void @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"()
// CHECK: define {{(linkonce_odr )?}}hidden void @_swift_dead_method_stub()
// CHECK: entry:
// CHECK: tail call void @swift_deletedMethodError()

Expand Down
8 changes: 6 additions & 2 deletions test/IRGen/zombies.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s

// Note: Windows uses internal linkage, which puts an extra step symbol before
// _swift_dead_method_stub.
// UNSUPPORTED: OS=windows-msvc

// rdar://24121475
// Ideally, these wouldn't be in the v-table at all; but as long as they
// are, we need to emit symbols for them.
Expand All @@ -8,8 +12,8 @@ class C {
init(i: Int) { self.i = i }
}

// CHECK: @"$s7zombies1CC1i33_{{.*}}vs" = hidden {{(dllexport )?}}alias void (), ptr @"$s7zombies1CC1i33_45489CBEFBF369AB7AEE3A799A95D78DLLSivg"
// CHECK: @"$s7zombies1CC1i33_{{.*}}vs" = hidden {{(dllexport )?}}alias void (), ptr @_swift_dead_method_stub

// CHECK: define hidden void @"$s7zombies1CC1i33_45489CBEFBF369AB7AEE3A799A95D78DLLSivg"()
// CHECK: define {{(linkonce_odr )?}}hidden void @_swift_dead_method_stub
// CHECK: entry:
// CHECK: tail call void @swift_deletedMethodError()
7 changes: 6 additions & 1 deletion test/embedded/linkage/leaf_application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public func unnecessary() -> Int64 { 5 }
@_neverEmitIntoClient
public func unusedYetThere() -> Int64 { 5 }

public class PointClass {
open class PointClass {
public var x, y: Int

public init(x: Int, y: Int) {
self.x = x
self.y = y
}

private func notUsed() { }
}

public protocol Reflectable: AnyObject {
Expand All @@ -89,6 +91,9 @@ public func createsExistential() -> any Reflectable {

// LIBRARY-IR-NOT: define {{.*}} @"$es27_allocateUninitializedArrayySayxG_BptBwlFSi_Tg5"


// LIBRARY-IR: define linkonce_odr hidden void @_swift_dead_method_stub

// LIBRARY-SIL: sil @$e7Library5helloSaySiGyF
// LIBRARY-SIL: sil @$e7Library8getArraySaySiGyF : $@convention(thin) () -> @owned Array<Int> {

Expand Down