File: static-init-wasm.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (82 lines) | stat: -rw-r--r-- 3,947 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -target-feature +bulk-memory -o - %s \
// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -target-feature +bulk-memory -o - %s \
// RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64

// Test that we don't create common blocks.
int tentative;
// WEBASSEMBLY32: @tentative = global i32 0, align 4
// WEBASSEMBLY64: @tentative = global i32 0, align 4

// Test that WebAssembly uses the ARM-style ABI in which the static
// variable's guard variable is tested via "load i8 and test the
// bottom bit" rather than the Itanium/x86 ABI which uses "load i8
// and compare with zero".
int f();
void g() {
  static int a = f();
}
// WEBASSEMBLY32-LABEL: @_Z1gv()
// WEBASSEMBLY32:       %[[R0:.+]] = load atomic i8, i8* bitcast (i32* @_ZGVZ1gvE1a to i8*) acquire, align 4
// WEBASSEMBLY32-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
// WEBASSEMBLY32-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
// WEBASSEMBLY32-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]],
// WEBASSEMBLY32:       [[CHECK]]
// WEBASSEMBLY32:       call i32 @__cxa_guard_acquire
// WEBASSEMBLY32:       [[END]]
// WEBASSEMBLY32:       call void @__cxa_guard_release
//
// WEBASSEMBLY64-LABEL: @_Z1gv()
// WEBASSEMBLY64:       %[[R0:.+]] = load atomic i8, i8* bitcast (i64* @_ZGVZ1gvE1a to i8*) acquire, align 8
// WEBASSEMBLY64-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
// WEBASSEMBLY64-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
// WEBASSEMBLY64-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]],
// WEBASSEMBLY64:       [[CHECK]]
// WEBASSEMBLY64:       call i32 @__cxa_guard_acquire
// WEBASSEMBLY64:       [[END]]
// WEBASSEMBLY64:       call void @__cxa_guard_release

// Test various aspects of static constructor calls.
struct A {
  A();
};

A theA;

// WEBASSEMBLY32: define internal void @__cxx_global_var_init() #3 {
// WEBASSEMBLY32: call noundef %struct.A* @_ZN1AC1Ev(%struct.A* {{[^,]*}} @theA)
// WEBASSEMBLY32: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #3 {
// WEBASSEMBLY32: call void @__cxx_global_var_init()
//
// WEBASSEMBLY64: define internal void @__cxx_global_var_init() #3 {
// WEBASSEMBLY64: call noundef %struct.A* @_ZN1AC1Ev(%struct.A* {{[^,]*}} @theA)
// WEBASSEMBLY64: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #3 {
// WEBASSEMBLY64: call void @__cxx_global_var_init()

// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm32-unknown-unknown -target-feature +bulk-memory -o - %s \
// RUN:   | FileCheck %s -check-prefix=NOATOMICS
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm64-unknown-unknown -target-feature +bulk-memory -o - %s \
// RUN:   | FileCheck %s -check-prefix=NOATOMICS

// NOATOMICS-LABEL: @_Z1gv()
// NOATOMICS:       %[[R0:.+]] = load i8, i8* @_ZGVZ1gvE1a, align 1
// NOATOMICS-NEXT:  %guard.uninitialized = icmp eq i8 %[[R0]], 0
// NOATOMICS-NEXT:  br i1 %guard.uninitialized, label %[[CHECK:.+]], label %[[END:.+]],
// NOATOMICS:       [[CHECK]]:
// NOATOMICS-NOT:   __cxa_guard_acquire
// NOATOMICS:       [[END]]:
// NOATOMICS-NEXT:  ret void

// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -o - %s \
// RUN:   | FileCheck %s -check-prefix=NOBULKMEM
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -o - %s \
// RUN:   | FileCheck %s -check-prefix=NOBULKMEM

// NOBULKMEM-LABEL: @_Z1gv()
// NOBULKMEM:       %[[R0:.+]] = load i8, i8* @_ZGVZ1gvE1a, align 1
// NOBULKMEM-NEXT:  %guard.uninitialized = icmp eq i8 %[[R0]], 0
// NOBULKMEM-NEXT:  br i1 %guard.uninitialized, label %[[CHECK:.+]], label %[[END:.+]],
// NOBULKMEM:       [[CHECK]]:
// NOBULKMEM-NOT:   __cxa_guard_acquire
// NOBULKMEM:       [[END]]:
// NOBULKMEM-NEXT:  ret void