Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/builtin-assume-aligned.cpp
T
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

63 lines
3.2 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s
int n;
constexpr int *p = 0;
// expected-error@+1 {{must be initialized by a constant expression}}
constexpr int *k = (int *) __builtin_assume_aligned(p, 16, n = 5);
constexpr void *l = __builtin_assume_aligned(p, 16);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{cast from 'void *' is not allowed in a constant expression}}
constexpr int *c = (int *) __builtin_assume_aligned(p, 16);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{alignment of the base pointee object (4 bytes) is less than the asserted 16 bytes}}
constexpr void *m = __builtin_assume_aligned(&n, 16);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{offset of the aligned pointer from the base pointee object (-2 bytes) is not a multiple of the asserted 4 bytes}}
constexpr void *q1 = __builtin_assume_aligned(&n, 4, 2);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 4 bytes}}
constexpr void *q2 = __builtin_assume_aligned(&n, 4, -2);
constexpr void *q3 = __builtin_assume_aligned(&n, 4, 4);
constexpr void *q4 = __builtin_assume_aligned(&n, 4, -4);
static char ar1[6];
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{alignment of the base pointee object (1 byte) is less than the asserted 16 bytes}}
constexpr void *r1 = __builtin_assume_aligned(&ar1[2], 16);
static char ar2[6] __attribute__((aligned(32)));
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 16 bytes}}
constexpr void *r2 = __builtin_assume_aligned(&ar2[2], 16);
constexpr void *r3 = __builtin_assume_aligned(&ar2[2], 16, 2);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{offset of the aligned pointer from the base pointee object (1 byte) is not a multiple of the asserted 16 bytes}}
constexpr void *r4 = __builtin_assume_aligned(&ar2[2], 16, 1);
constexpr int* x = __builtin_constant_p((int*)0xFF) ? (int*)0xFF : (int*)0xFF;
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{value of the aligned pointer (255) is not a multiple of the asserted 32 bytes}}
constexpr void *s1 = __builtin_assume_aligned(x, 32);
// expected-error@+2 {{must be initialized by a constant expression}}
// expected-note@+1 {{value of the aligned pointer (250) is not a multiple of the asserted 32 bytes}}
constexpr void *s2 = __builtin_assume_aligned(x, 32, 5);
constexpr void *s3 = __builtin_assume_aligned(x, 32, -1);
constexpr int add(int a, int b) {
return a+b;
}
constexpr void *c1 = __builtin_assume_aligned(p, add(1,1));
constexpr void *c2 = __builtin_assume_aligned(p, add(2,1)); // expected-error {{not a power of 2}}
constexpr long kAlignment = 128;
long AllocateAlignedBytes_payload;
void AllocateAlignedBytes() {
void *m = __builtin_assume_aligned(
reinterpret_cast<void *>(AllocateAlignedBytes_payload), kAlignment);
}