Skip to content

Embedded wasm32-unknown-none-wasm incorrectly calls class destructor with C_CC #72343

@kateinoigakukun

Description

@kateinoigakukun

Description

We check availability of swiftasynccc feature to detect if the target support swiftcc here https://github.com/apple/swift/blob/735e28b551e13262c2ff0ce013608a2202d5b8b6/stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h#L32

But wasm target doesn't support swiftasynccc but does swiftcc, so _swift_embedded_invoke_heap_object_destroy calls destructor functions without swiftcc even though compiler emits destructor definitions with swiftcc.

Reproduction

// RUN: split-file %s %t
// RUN: %target-swiftc_driver %t/check.swift -Xclang-linker %t/rt.c -target wasm32-unknown-none-wasm \
// RUN:   -enable-experimental-feature Embedded -Xcc -fdeclspec -wmo -Xfrontend -disable-stack-protector \
// RUN:   -Xclang-linker -nostdlib -o %t/check.wasm
// RUN: %target-run %t/check.wasm

// -- rt.c

#include <stddef.h>
#include <stdint.h>

void free(void *ptr) {}

int posix_memalign(void **memptr, size_t alignment, size_t size) {
    uintptr_t mem = __builtin_wasm_memory_grow(0, (size + 0xffff) / 0x10000);
    if (mem == -1) {
        return -1;
    }
    *memptr = (void *)(mem * 0x10000);
    *memptr = (void *)(((uintptr_t)*memptr + alignment - 1) & -alignment);
    return 0;
}

// -- check.swift

class Foo {}

@_cdecl("_start")
func main() {
  _ = Foo()
}

Expected behavior

No CC mismatch

Environment

3d4457b

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    WebAssemblyPlatform: WebAssemblybugA deviation from expected or documented behavior. Also: expected but undesirable behavior.embeddedEmbedded Swift

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions