brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.3 KiB · 9075e9e Raw
90 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -triple wasm32 -target-feature +reference-types %s2// RUN: %clang_cc1 -fsyntax-only -verify -triple wasm32 -target-abi experimental-mv -DMULTIVALUE -target-feature +reference-types %s3 4#define EXPR_HAS_TYPE(expr, type) _Generic((expr), type : 1, default : 0)5 6static __externref_t table[0];7 8typedef void (*__funcref funcref_t)();9void test_ref_null() {10  funcref_t func = __builtin_wasm_ref_null_func(0); // expected-error {{too many arguments to function call, expected 0, have 1}}11  __externref_t ref = __builtin_wasm_ref_null_extern(0); // expected-error {{too many arguments to function call, expected 0, have 1}}12  __builtin_wasm_ref_is_null_extern(ref, 1); // expected-error {{too many arguments to function call, expected 1, have 2}}13  __builtin_wasm_ref_is_null_extern(); // expected-error {{too few arguments to function call, expected 1, have 0}}14  __builtin_wasm_ref_is_null_extern(1); // expected-error {{1st argument must be an externref}}15}16 17void test_table_size(__externref_t ref, void *ptr, int arr[]) {18  __builtin_wasm_table_size();                        // expected-error {{too few arguments to function call, expected 1, have 0}}19  __builtin_wasm_table_size(1);                       // expected-error {{1st argument must be a WebAssembly table}}20  __builtin_wasm_table_size(ref);                     // expected-error {{1st argument must be a WebAssembly table}}21  __builtin_wasm_table_size(ptr);                     // expected-error {{1st argument must be a WebAssembly table}}22  __builtin_wasm_table_size(arr);                     // expected-error {{1st argument must be a WebAssembly table}}23  __builtin_wasm_table_size(table, table);            // expected-error {{too many arguments to function call, expected 1, have 2}}24 25  _Static_assert(EXPR_HAS_TYPE(__builtin_wasm_table_size(table), unsigned long), "");26}27 28void test_table_grow(__externref_t ref, int size) {29  __builtin_wasm_table_grow();                           // expected-error {{too few arguments to function call, expected 3, have 0}}30  __builtin_wasm_table_grow(table, table, table, table); // expected-error {{too many arguments to function call, expected 3, have 4}}31  __builtin_wasm_table_grow(ref, ref, size);             // expected-error {{1st argument must be a WebAssembly table}}32  __builtin_wasm_table_grow(table, table, size);         // expected-error {{2nd argument must match the element type of the WebAssembly table in the 1st argument}}33  __builtin_wasm_table_grow(table, ref, table);          // expected-error {{3rd argument must be an integer}}34 35  _Static_assert(EXPR_HAS_TYPE(__builtin_wasm_table_grow(table, ref, size), int), "");36}37 38void test_table_fill(int index, __externref_t ref, int nelem) {39  __builtin_wasm_table_fill();                                   // expected-error {{too few arguments to function call, expected 4, have 0}}40  __builtin_wasm_table_fill(table, table, table, table, table);  // expected-error {{too many arguments to function call, expected 4, have 5}}41  __builtin_wasm_table_fill(index, index, ref, nelem);           // expected-error {{1st argument must be a WebAssembly table}}42  __builtin_wasm_table_fill(table, table, ref, nelem);           // expected-error {{2nd argument must be an integer}}43  __builtin_wasm_table_fill(table, index, index, ref);           // expected-error {{3rd argument must match the element type of the WebAssembly table in the 1st argument}}44  __builtin_wasm_table_fill(table, index, ref, table);           // expected-error {{4th argument must be an integer}}45  __builtin_wasm_table_fill(table, index, ref, nelem);46}47 48void test_table_copy(int dst_idx, int src_idx, int nelem) {49  __builtin_wasm_table_copy();                                         // expected-error {{too few arguments to function call, expected 5, have 0}}50  __builtin_wasm_table_copy(table, table, table, table, table, table); // expected-error {{too many arguments to function call, expected 5, have 6}}51  __builtin_wasm_table_copy(src_idx, table, dst_idx, src_idx, nelem);  // expected-error {{1st argument must be a WebAssembly table}}52  __builtin_wasm_table_copy(table, src_idx, dst_idx, src_idx, nelem);  // expected-error {{2nd argument must be a WebAssembly table}}53  __builtin_wasm_table_copy(table, table, table, src_idx, nelem);      // expected-error {{3rd argument must be an integer}}54  __builtin_wasm_table_copy(table, table, dst_idx, table, nelem);      // expected-error {{4th argument must be an integer}}55  __builtin_wasm_table_copy(table, table, dst_idx, src_idx, table);    // expected-error {{5th argument must be an integer}}56  __builtin_wasm_table_copy(table, table, dst_idx, src_idx, nelem);57}58 59typedef void (*F1)(void);60typedef int (*F2)(int);61typedef void (*F3)(struct {int x; double y;});62typedef struct {int x; double y;} (*F4)(void);63 64void test_function_pointer_signature() {65  // Test argument count validation66  (void)__builtin_wasm_test_function_pointer_signature(); // expected-error {{too few arguments to function call, expected 1, have 0}}67  (void)__builtin_wasm_test_function_pointer_signature((F1)0, (F2)0); // expected-error {{too many arguments to function call, expected 1, have 2}}68 69  // // Test argument type validation - should require function pointer70  (void)__builtin_wasm_test_function_pointer_signature((void*)0); // expected-error {{used type 'void *' where function pointer is required}}71  (void)__builtin_wasm_test_function_pointer_signature((int)0);   // expected-error {{used type 'int' where function pointer is required}}72 73  // // Test valid usage74  int res = __builtin_wasm_test_function_pointer_signature((F1)0);75  res = __builtin_wasm_test_function_pointer_signature((F2)0);76 77  // Test return type78  _Static_assert(EXPR_HAS_TYPE(__builtin_wasm_test_function_pointer_signature((F1)0), int), "");79 80#ifdef MULTIVALUE81  // Test that struct arguments and returns are rejected with multivalue abi82  (void)__builtin_wasm_test_function_pointer_signature((F3)0); // expected-error {{not supported with the multivalue ABI for function pointers with a struct/union as parameter}}83  (void)__builtin_wasm_test_function_pointer_signature((F4)0); // expected-error {{not supported with the multivalue ABI for function pointers with a struct/union as return value}}84#else85  // with default abi they are fine86  (void)__builtin_wasm_test_function_pointer_signature((F3)0);87  (void)__builtin_wasm_test_function_pointer_signature((F4)0);88#endif89}90