Skip to content

Commit 96e7118

Browse files
[test] Add a test for class allocation on Embedded Wasm
1 parent ca41590 commit 96e7118

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

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)