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
88 lines
4.2 KiB
C++
88 lines
4.2 KiB
C++
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-max=0
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-mode=typehash -DMODE_TYPEHASH
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2
|
|
// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2
|
|
// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2 -fexperimental-new-constant-interpreter
|
|
|
|
#if !__has_builtin(__builtin_infer_alloc_token)
|
|
#error "missing __builtin_infer_alloc_token"
|
|
#endif
|
|
|
|
struct NoPtr {
|
|
int x;
|
|
long y;
|
|
};
|
|
|
|
struct WithPtr {
|
|
int a;
|
|
char *buf;
|
|
};
|
|
|
|
// Check specific known values; these are guaranteed to be stable.
|
|
#ifdef MODE_TYPEHASH
|
|
static_assert(__builtin_infer_alloc_token(sizeof(int)) == 2689373973731826898ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(char*)) == 2250492667400517147ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(NoPtr)) == 7465259095297095368ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(WithPtr)) == 11898882936532569145ULL);
|
|
#elif defined(TOKEN_MAX)
|
|
# if TOKEN_MAX == 2
|
|
static_assert(__builtin_infer_alloc_token(sizeof(int)) == 0);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(char*)) == 1);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(NoPtr)) == 0);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(WithPtr)) == 1);
|
|
# else
|
|
# error "unhandled TOKEN_MAX case"
|
|
# endif
|
|
#else
|
|
static_assert(__builtin_infer_alloc_token(sizeof(int)) == 2689373973731826898ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(char*)) == 11473864704255292954ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(NoPtr)) == 7465259095297095368ULL);
|
|
static_assert(__builtin_infer_alloc_token(sizeof(WithPtr)) == 11898882936532569145ULL);
|
|
#endif
|
|
|
|
// Template function.
|
|
template <typename T>
|
|
constexpr unsigned long get_token() {
|
|
return __builtin_infer_alloc_token(sizeof(T));
|
|
}
|
|
static_assert(__builtin_infer_alloc_token(sizeof(int)) == get_token<int>());
|
|
|
|
// Test complex expressions.
|
|
static_assert(__builtin_constant_p(__builtin_infer_alloc_token(sizeof(int))));
|
|
static_assert(__builtin_infer_alloc_token(sizeof(NoPtr) * 2, 1) == get_token<NoPtr>());
|
|
static_assert(__builtin_infer_alloc_token(1, 4 + sizeof(NoPtr)) == get_token<NoPtr>());
|
|
static_assert(__builtin_infer_alloc_token(sizeof(NoPtr) << 8) == get_token<NoPtr>());
|
|
|
|
// Test usable as a template param.
|
|
template <unsigned long ID, typename T>
|
|
struct token_for_type {
|
|
static_assert(ID == get_token<T>());
|
|
static constexpr unsigned long value = ID;
|
|
};
|
|
static_assert(token_for_type<__builtin_infer_alloc_token(sizeof(int)), int>::value == get_token<int>());
|
|
|
|
template <typename T = void>
|
|
void template_test() {
|
|
__builtin_infer_alloc_token(T()); // no error if not instantiated
|
|
}
|
|
|
|
template <typename T>
|
|
void negative_template_test() {
|
|
__builtin_infer_alloc_token(T()); // expected-error {{argument may not have 'void' type}}
|
|
}
|
|
|
|
void negative_tests() {
|
|
__builtin_infer_alloc_token(); // expected-error {{too few arguments to function call}}
|
|
__builtin_infer_alloc_token((void)0); // expected-error {{argument may not have 'void' type}}
|
|
negative_template_test<void>(); // expected-note {{in instantiation of function template specialization 'negative_template_test<void>' requested here}}
|
|
constexpr auto inference_fail = __builtin_infer_alloc_token(123); // expected-error {{must be initialized by a constant expression}} \
|
|
// expected-note {{could not infer allocation type for __builtin_infer_alloc_token}}
|
|
|
|
// PR178892: Ensure struct arguments don't crash the bytecode interpreter.
|
|
struct S {};
|
|
constexpr auto struct_arg = __builtin_infer_alloc_token(S()); // expected-error {{must be initialized by a constant expression}} \
|
|
// expected-note {{could not infer allocation type for __builtin_infer_alloc_token}}
|
|
}
|