Files
swift-mirror/test/IRGen/c_implementation.swift
Saleem Abdulrasool cf7a850035 IRGen: preserve imported C and C++ calling conventions
IRGen rebuilt imported C function and C++ method signatures with the
platform C convention, even when their Clang types specified a different
convention. This made indirect calls, @implementation @c definitions, and
C++ method calls disagree with their declarations on targets such as
32-bit Windows.

Preserve the original Clang type for imported C++ methods in SIL. Pass
conventions that differ from the platform C default through ABI arrangement
and use the resulting LLVM convention. Compare against the free-function
default so that the default thiscall convention for Win32 instance methods
is preserved, while ordinary C calls retain the platform convention.

With -use-clang-function-types, cover C definitions, direct and indirect
calls, and C++ instance methods using default thiscall, explicit stdcall,
and explicit cdecl conventions.
2026-09-12 14:50:38 -07:00

61 lines
1.9 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
// RUN: -disable-objc-interop \
// RUN: -F %clang-importer-sdk-path/frameworks %s \
// RUN: -import-objc-header %S/Inputs/objc_implementation.h -emit-ir \
// RUN: -use-clang-function-types \
// RUN: -target %target-future-triple > %t.ir
// RUN: %FileCheck --input-file %t.ir %s
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
// RUN: -disable-objc-interop \
// RUN: -F %clang-importer-sdk-path/frameworks %s \
// RUN: -import-objc-header %S/Inputs/objc_implementation.h -emit-sil \
// RUN: -use-clang-function-types \
// RUN: -experimental-print-full-convention \
// RUN: -target %target-future-triple | %FileCheck %s --check-prefix=SIL
@implementation @c
public func implFunc(_ param: Int32) {}
@implementation @c
public func implFuncCName(_ param: Int32) {}
@implementation @c(implFuncRenamed_C)
public func implFuncRenamed_Swift(param: Int32) {}
@implementation @c
public func implFuncSwiftCall(_ param: Int32) -> Int32 {
return param
}
public func fn() {
implFunc(2)
implFuncCName(3)
implFuncRenamed_Swift(param: 4)
_ = implFuncSwiftCall(5)
}
/// implFunc(_:)
// CHECK-LABEL: define{{.*}} void @implFunc
// CHECK-NOT: define{{.*}} swiftcc void @"$s16c_implementation8implFuncyys5Int32VF"
/// inplFuncCName(_:)
// CHECK-LABEL: define{{.*}} void @"\01_implFuncAsmName"
// CHECK-NOT: define{{.*}} swiftcc void @"$s16c_implementation13implFuncCNameyys5Int32VF"
/// implFuncSwiftCall(_:)
// SIL-LABEL: sil [asmname "implFuncSwiftCall"]
// SIL-SAME: @convention(c, cType:
// SIL-SAME: swiftcall
// CHECK-LABEL: define{{.*}} swiftcc i32 @implFuncSwiftCall
/// fn()
// CHECK-LABEL: define{{.*}} swiftcc void @"$s16c_implementation2fnyyF"
// CHECK: call void @implFunc
// CHECK: call void @"\01_implFuncAsmName"
// CHECK: call void @implFuncRenamed_C
// CHECK: call swiftcc i32 @implFuncSwiftCall
// CHECK: ret void
// CHECK: }