Skip to content

[embedded] Use __has_feature(swiftcc) to detect Swift calling convention #72345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kateinoigakukun
Copy link
Member

This change replaces the use of __has_feature(swiftasynccc) with __has_feature(swiftcc) to detect the SwiftCC availability. The former condition works fine for most platforms that support both SwiftCC and SwiftAsyncCC or neither, but it fails for WebAssembly, which supports SwiftCC but not SwiftAsyncCC.

This change depends on llvm/llvm-project#85347

Close #72343

@kateinoigakukun kateinoigakukun requested a review from a team as a code owner March 15, 2024 03:27
@kubamracek
Copy link
Contributor

If https://github.com/llvm/llvm-project/pull/85347/files causes __has_feature(swiftasynccc) to stop working, then we also need to adjust Runtime/Config.h.

@kateinoigakukun kateinoigakukun force-pushed the katei/has-feature-swiftcall branch from cc3c83a to 864779e Compare March 20, 2024 04:13
@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test WebAssembly

@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test

@kubamracek kubamracek requested review from compnerd and rauhul March 20, 2024 16:42
// RUN: %clang -target wasm32-unknown-none-wasm %t/check.o %t/rt.c -nostdlib -o %t/check.wasm
// RUN: %target-run %t/check.wasm
// REQUIRES: executable_test
// REQUIRES: CPU=wasm32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point me to a CI job that actually runs these executable WASM tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasm CI runs executable tests on WasmKit runtime: https://ci.swift.org/job/swift-PR-Linux-crosscompile-wasm/31

@@ -28,8 +28,7 @@
extern "C" {
#endif

// FIXME: Replace with __has_feature(swiftcc) once that's added to Clang.
#if __has_feature(swiftasynccc)
#if __has_extension(swiftcc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use __has_feature(swiftasynccc) || __has_extension(swiftcc) to be compatible with older compilers for a while?

@compnerd Do all windows builds use a just built compiler such that this is not a concern?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth being conservative here.

…vention

This change replaces the use of `__has_feature(swiftasynccc)` with
`__has_extension(swiftcc)` to detect the SwiftCC availability. The former
condition works fine for most platforms that support both SwiftCC and
SwiftAsyncCC or neither, but it fails for WebAssembly, which supports
SwiftCC but not SwiftAsyncCC.

We add `swiftcc` extension to Clang, and use it here.
@kateinoigakukun kateinoigakukun force-pushed the katei/has-feature-swiftcall branch from 864779e to 5c26620 Compare March 20, 2024 23:07
@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test

@kateinoigakukun kateinoigakukun force-pushed the katei/has-feature-swiftcall branch from 5c26620 to 1e11d0f Compare March 21, 2024 21:31
@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test

@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test WebAssembly

@kateinoigakukun
Copy link
Member Author

Hmm, #if __has_attribute(swiftasynccall) && (__has_feature(swiftasynccc) || __has_extension(swiftasynccc)) is not acceptable with MSVC cl.exe?

https://ci-external.swift.org/job/swift-PR-windows/23188/console

C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\include\swift/Runtime/Config.h(231): fatal error C1012: unmatched parenthesis: missing ')'
  // SWIFT_CC(swiftasync) is the Swift async calling convention.
  // We assume that it supports mandatory tail call elimination.
  #if __has_attribute(swiftasynccall) && (__has_feature(swiftasynccc) || __has_extension(swiftasynccc))
  #define SWIFT_CC_swiftasync __attribute__((swiftasynccall))
  #else
  #define SWIFT_CC_swiftasync SWIFT_CC_swift
  #endif

`swiftasynccc` is now an extension instead of a feature, so we should
use `__has_extension` to detect its availability.
@kateinoigakukun kateinoigakukun force-pushed the katei/has-feature-swiftcall branch from 1e11d0f to 1f91d95 Compare March 26, 2024 05:13
@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test

@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test WebAssembly

@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test

@kateinoigakukun
Copy link
Member Author

Please test with following PR:
swiftlang/llvm-project#8441

@swift-ci Please test WebAssembly

@kateinoigakukun kateinoigakukun merged commit 52e8fbc into swiftlang:main Mar 27, 2024
@kateinoigakukun kateinoigakukun deleted the katei/has-feature-swiftcall branch April 4, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embedded wasm32-unknown-none-wasm incorrectly calls class destructor with C_CC
3 participants