Skip to content

@_cdecl function doesn't properly inline imported C content #85112

@rauhul

Description

@rauhul

Description

C decl functions aren't inlining imported C functions marked with always_inline, see repro. This works for regular swift functions.

Reproduction

#pragma once

extern int my_malloc(int);

__attribute__((always_inline))
static inline int my_c_func() {
  return my_malloc(1);
}
import cmod

public func swift_entry() {
  print(my_c_func()) // Reduces to call to my_malloc
}

@_cdecl("c_entry")
func c_entry() {
  print(my_c_func()) // Calls my_c_func
}

Use ./build.sh to repro in:
repro.zip

Building

Searching for _my_c_func in c decl function (bad!)
      84: 94000000      bl      0x84 <_c_entry+0x34>
                0000000000000084:  ARM64_RELOC_BRANCH26 _my_c_func
      88: 90000008      adrp    x8, 0x0 <ltmp0>

Searching for _my_malloc in swift function (good!)
      f8: 94000000      bl      0xf8 <_$s3foo11swift_entryyyFTm+0x38>
                00000000000000f8:  ARM64_RELOC_BRANCH26 _my_malloc
      fc: 90000008      adrp    x8, 0x0 <ltmp0>

Expected behavior

_cdecl functions should properly inline imported always inline c functions.

Environment

swift-driver version: 1.127.9 Apple Swift version 6.2 (swiftlang-6.2.0.13.10 clang-1700.3.13.4)
Target: arm64-apple-macosx26.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions