File: wasm-refs-and-tables.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (30 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -verify -triple wasm32 -Wno-unused-value -target-feature +reference-types %s
// RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -fexceptions -fsyntax-only -verify -triple wasm32 -Wno-unused-value -target-feature +reference-types %s

// 
// Note: As WebAssembly references are sizeless types, we don't exhaustively
// test for cases covered by sizeless-1.c and similar tests.

// Using c++11 to test dynamic exception specifications (which are not 
// allowed in c++17).

// Unlike standard sizeless types, reftype globals are supported.
__externref_t r1;
static __externref_t table[0];

#if (_cplusplus == 201103L)
__externref_t func(__externref_t ref)  throw(__externref_t) { // expected-error {{WebAssembly reference type not allowed in exception specification}}
  return ref;
}
#endif

void *ret_void_ptr() {
  throw table;              // expected-error {{cannot throw a WebAssembly reference type}}
  throw r1;                 // expected-error {{cannot throw a WebAssembly reference type}}
  try {}
  catch (__externref_t T) { // expected-error {{cannot catch a WebAssembly reference type}}
    (void)0;
  }

  return table;             // expected-error {{cannot return a WebAssembly table}}
}