Skip to content

Compiler Crash During C Function Pointer Interop #82360

Open
@tothambrus11

Description

@tothambrus11

Description

In Swift 6.2 development snapshot, the attached C-Swift interop crashes the compiler with the following message (though it works in 6.1):

<unknown>:0: error: symbol 'add' (add) is in generated IR file, but not in TBD file
<unknown>:0: error: symbol 'returning_lambda' (returning_lambda) is in generated IR file, but not in TBD file
<unknown>:0: error: symbol 'taking_lambda' (taking_lambda) is in generated IR file, but not in TBD file

Any of the attempts of using the C functions involving function pointers results in this crash individually, but in Swift 6.1, all of them work.

Reproduction

int taking_lambda(int (*f)(int, int), int a, int b) {
  return f(a, b);
}

int add(int a, int b) {
  return a + b;
}

typedef int (*ReturningLambdaType)(int, int);

ReturningLambdaType returning_lambda () {
  return &add;
}
func f(a: Int32, b: Int32) -> Int32 {
    return a + b
}
let a1 = taking_lambda(f, 2, 3)
print("kfwe: \(a1)")

let a2 = taking_lambda({ a, b in a + b }, 2, 3)
print(a2)

let a3 = returning_lambda()
print(a3!(2,4))

Stack dump

It was a peaceful crash with errors reported.


<unknown>:0: error: symbol 'add' (add) is in generated IR file, but not in TBD file
<unknown>:0: error: symbol 'returning_lambda' (returning_lambda) is in generated IR file, but not in TBD file
<unknown>:0: error: symbol 'taking_lambda' (taking_lambda) is in generated IR file, but not in TBD file

Expected behavior

Compile and run the code as expected in 6.1.

Environment

6.2-snapshot-2025-06-14

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage 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