Files
TheRock/compiler/amd-llvm/clang/test/Sema/attr-overflow-behavior-constexpr.cpp
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

61 lines
1.9 KiB
C++

// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -fexperimental-overflow-behavior-types -verify -fsyntax-only -std=c++14
// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -fexperimental-overflow-behavior-types -verify -fsyntax-only -std=c++14 -fexperimental-new-constant-interpreter
#define __wrap __attribute__((overflow_behavior(wrap)))
#define __no_trap __attribute__((overflow_behavior(trap)))
typedef int __ob_wrap wrap_int;
typedef int __ob_trap no_trap_int;
constexpr wrap_int add(wrap_int a, wrap_int b) {
return a + b;
}
constexpr no_trap_int sub(no_trap_int a, no_trap_int b) {
return a - b; // expected-note {{value -2147483649 is outside the range of representable values of type 'no_trap_int' (aka '__ob_trap int')}}
}
constexpr wrap_int preinc(wrap_int a) {
++a;
return a;
}
constexpr wrap_int postinc(wrap_int a) {
a++;
return a;
}
void constexpr_test() {
constexpr wrap_int max = 2147483647;
constexpr wrap_int one = 1;
static_assert(add(max, one) == -2147483648, "constexpr wrapping failed");
constexpr no_trap_int min = -2147483648;
constexpr no_trap_int one_nw = 1;
constexpr no_trap_int res = sub(min, one_nw); // expected-error {{constexpr variable 'res' must be initialized by a constant expression}} expected-note {{in call to 'sub(-2147483648, 1)'}}
static_assert(preinc(max) == -2147483648, "preinc wrapping failed");
static_assert(postinc(max) == -2147483648, "postinc wrapping failed");
constexpr wrap_int M = -2147483648;
constexpr wrap_int A = -M;
}
template <typename T>
void check_deduction_wrap(T) {
static_assert(__is_same(T, wrap_int), "T should be deduced as wrap_int");
}
template <typename T>
void check_deduction_no_trap(T) {
static_assert(__is_same(T, no_trap_int), "T should be deduced as no_trap_int");
}
void template_deduction_test() {
wrap_int w = 0;
check_deduction_wrap(w);
no_trap_int nw = 0;
check_deduction_no_trap(nw);
}