Skip to content

Explicit calling convention specifier on imported C functions are ignored #69264

@kateinoigakukun

Description

@kateinoigakukun

Description

swift-atomics has a C header imported by Swift, and it contains a C function declaration with SwiftCC.
https://github.com/apple/swift-atomics/blob/cd142fd2f64be2100422d658e7411e39489da985/Sources/_AtomicsShims/include/_AtomicsShims.h#L25

However, the caller side of the function does not use SwiftCC, and it causes calling convention violation.

Steps to reproduce

Here is a lit test case to reproduce the issue

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -I%t %t/caller.swift -emit-ir | %FileCheck %s

//--- c_funcs.h

__attribute__((swiftcall))
extern void with_swiftcc(void);

//--- module.modulemap

module c_funcs {
  header "c_funcs.h"
}

//--- caller.swift

import c_funcs

func test() {
  // CHECK: call swiftcc void @with_swiftcc()
  with_swiftcc()
}
// CHECK: declare swiftcc void @with_swiftcc()

test()

Environment

  • Swift compiler version info 41dc466

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c interopFeature: Interoperability with C

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions