CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
152 lines
3.3 KiB
C++
152 lines
3.3 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <cassert>
|
|
#include <cxxabi.h>
|
|
|
|
#include "test_macros.h"
|
|
|
|
#ifndef TEST_HAS_NO_THREADS
|
|
# include <thread>
|
|
# include "make_test_thread.h"
|
|
#endif
|
|
|
|
// Ensure that we initialize each variable once and only once.
|
|
namespace test1 {
|
|
static int run_count = 0;
|
|
int increment() {
|
|
++run_count;
|
|
return 0;
|
|
}
|
|
void helper() {
|
|
static int a = increment();
|
|
((void)a);
|
|
}
|
|
void test() {
|
|
static int a = increment(); ((void)a);
|
|
assert(run_count == 1);
|
|
static int b = increment(); ((void)b);
|
|
assert(run_count == 2);
|
|
helper();
|
|
assert(run_count == 3);
|
|
helper();
|
|
assert(run_count == 3);
|
|
}
|
|
}
|
|
|
|
// When initialization fails, ensure that we try to initialize it again next
|
|
// time.
|
|
namespace test2 {
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
|
static int run_count = 0;
|
|
int increment() {
|
|
++run_count;
|
|
throw 0;
|
|
}
|
|
void helper() {
|
|
try {
|
|
static int a = increment();
|
|
assert(false);
|
|
((void)a);
|
|
} catch (...) {}
|
|
}
|
|
void test() {
|
|
helper();
|
|
assert(run_count == 1);
|
|
helper();
|
|
assert(run_count == 2);
|
|
}
|
|
#else
|
|
void test() {}
|
|
#endif
|
|
}
|
|
|
|
// Check that we can initialize a second value while initializing a first.
|
|
namespace test3 {
|
|
int zero() {
|
|
return 0;
|
|
}
|
|
|
|
int one() {
|
|
static int b = zero(); ((void)b);
|
|
return 0;
|
|
}
|
|
|
|
void test() {
|
|
static int a = one(); ((void)a);
|
|
}
|
|
}
|
|
|
|
#ifndef TEST_HAS_NO_THREADS
|
|
// A simple thread test of two threads racing to initialize a variable. This
|
|
// isn't guaranteed to catch any particular threading problems.
|
|
namespace test4 {
|
|
static int run_count = 0;
|
|
int increment() {
|
|
++run_count;
|
|
return 0;
|
|
}
|
|
|
|
void helper() {
|
|
static int a = increment(); ((void)a);
|
|
}
|
|
|
|
void test() {
|
|
std::thread t1 = support::make_test_thread(helper);
|
|
std::thread t2 = support::make_test_thread(helper);
|
|
t1.join();
|
|
t2.join();
|
|
assert(run_count == 1);
|
|
}
|
|
}
|
|
|
|
// Check that we don't re-initialize a static variable even when it's
|
|
// encountered from two different threads.
|
|
namespace test5 {
|
|
static int run_count = 0;
|
|
int zero() {
|
|
++run_count;
|
|
return 0;
|
|
}
|
|
|
|
int one() {
|
|
static int b = zero(); ((void)b);
|
|
return 0;
|
|
}
|
|
|
|
void another_helper() {
|
|
static int a = one(); ((void)a);
|
|
}
|
|
|
|
void helper() {
|
|
static int a = one(); ((void)a);
|
|
std::thread t = support::make_test_thread(another_helper);
|
|
t.join();
|
|
}
|
|
|
|
void test() {
|
|
std::thread t = support::make_test_thread(helper);
|
|
t.join();
|
|
assert(run_count == 1);
|
|
}
|
|
}
|
|
#endif /* TEST_HAS_NO_THREADS */
|
|
|
|
int main(int, char**)
|
|
{
|
|
test1::test();
|
|
test2::test();
|
|
test3::test();
|
|
#ifndef TEST_HAS_NO_THREADS
|
|
test4::test();
|
|
test5::test();
|
|
#endif
|
|
|
|
return 0;
|
|
}
|