Files
RedBear-OS/local/recipes/dev/libclc/source/clang/test/CodeGenCXX/static-init-wasm.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

83 lines
3.7 KiB
C++

// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=WEBASSEMBLY32
// RUN: %clang_cc1 -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, ptr @_ZGVZ1gvE1a 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, ptr @_ZGVZ1gvE1a 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 ptr @_ZN1AC1Ev(ptr {{[^,]*}} @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 ptr @_ZN1AC1Ev(ptr {{[^,]*}} @theA)
// WEBASSEMBLY64: define internal void @_GLOBAL__sub_I_static_init_wasm.cpp() #3 {
// WEBASSEMBLY64: call void @__cxx_global_var_init()
// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +bulk-memory -o - %s \
// RUN: | FileCheck %s -check-prefix=NOATOMICS
// RUN: %clang_cc1 -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, ptr @_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 -emit-llvm -triple=wasm32-unknown-unknown -target-feature +atomics -o - %s \
// RUN: | FileCheck %s -check-prefix=NOBULKMEM
// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -target-feature +atomics -o - %s \
// RUN: | FileCheck %s -check-prefix=NOBULKMEM
// NOBULKMEM-LABEL: @_Z1gv()
// NOBULKMEM: %[[R0:.+]] = load i8, ptr @_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