Skip to content

Commit 52e8fbc

Browse files
Merge pull request #72345 from kateinoigakukun/katei/has-feature-swiftcall
[embedded] Use `__has_feature(swiftcc)` to detect Swift calling convention
2 parents 1a0bcb2 + 1f91d95 commit 52e8fbc

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

include/swift/Runtime/Config.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ extern uintptr_t __COMPATIBILITY_LIBRARIES_CANNOT_CHECK_THE_IS_SWIFT_BIT_DIRECTL
228228

229229
// SWIFT_CC(swiftasync) is the Swift async calling convention.
230230
// We assume that it supports mandatory tail call elimination.
231-
#if __has_feature(swiftasynccc) && __has_attribute(swiftasynccall)
232-
#define SWIFT_CC_swiftasync __attribute__((swiftasynccall))
231+
#if __has_attribute(swiftasynccall)
232+
# if __has_feature(swiftasynccc) || __has_extension(swiftasynccc)
233+
# define SWIFT_CC_swiftasync __attribute__((swiftasynccall))
234+
# else
235+
# define SWIFT_CC_swiftasync SWIFT_CC_swift
236+
# endif
233237
#else
234238
#define SWIFT_CC_swiftasync SWIFT_CC_swift
235239
#endif

stdlib/public/SwiftShims/swift/shims/EmbeddedShims.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
extern "C" {
2929
#endif
3030

31-
// FIXME: Replace with __has_feature(swiftcc) once that's added to Clang.
32-
#if __has_feature(swiftasynccc)
31+
// TODO: __has_feature(swiftasynccc) is just for older clang. Remove this
32+
// when we no longer support older clang.
33+
#if __has_extension(swiftcc) || __has_feature(swiftasynccc)
3334
#define SWIFT_CC_swift __attribute__((swiftcall))
3435
#define SWIFT_CONTEXT __attribute__((swift_context))
3536
#define SWIFT_ERROR_RESULT __attribute__((swift_error_result))

test/embedded/classes-wasm.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %swift-frontend -c %t/check.swift -parse-as-library -target wasm32-unknown-none-wasm \
4+
// RUN: -enable-experimental-feature Embedded -Xcc -fdeclspec -disable-stack-protector \
5+
// RUN: -o %t/check.o
6+
// RUN: %clang -target wasm32-unknown-none-wasm %t/check.o %t/rt.c -nostdlib -o %t/check.wasm
7+
// RUN: %target-run %t/check.wasm
8+
// REQUIRES: executable_test
9+
// REQUIRES: CPU=wasm32
10+
11+
//--- rt.c
12+
13+
#include <stddef.h>
14+
#include <stdint.h>
15+
16+
void free(void *ptr) {}
17+
18+
int posix_memalign(void **memptr, size_t alignment, size_t size) {
19+
uintptr_t mem = __builtin_wasm_memory_grow(0, (size + 0xffff) / 0x10000);
20+
if (mem == -1) {
21+
return -1;
22+
}
23+
*memptr = (void *)(mem * 0x10000);
24+
*memptr = (void *)(((uintptr_t)*memptr + alignment - 1) & -alignment);
25+
return 0;
26+
}
27+
28+
//--- check.swift
29+
30+
class Foo {}
31+
32+
@_cdecl("_start")
33+
func main() {
34+
_ = Foo()
35+
}

utils/swift_build_support/swift_build_support/products/wasmstdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def build(self, host_target):
101101
# Test configuration
102102
self.cmake_options.define('SWIFT_INCLUDE_TESTS:BOOL', 'TRUE')
103103
self.cmake_options.define('SWIFT_ENABLE_SOURCEKIT_TESTS:BOOL', 'FALSE')
104-
lit_test_paths = ['IRGen', 'stdlib', 'Concurrency/Runtime']
104+
lit_test_paths = ['IRGen', 'stdlib', 'Concurrency/Runtime', 'embedded']
105105
lit_test_paths = [os.path.join(
106106
self.build_dir, 'test-wasi-wasm32', path) for path in lit_test_paths]
107107
self.cmake_options.define('SWIFT_LIT_TEST_PATHS:STRING',

0 commit comments

Comments
 (0)