[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / builtin-assume-aligned.cpp
blob48bd8414fc50a10d56c4db878216e0809680c75c
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s
3 int n;
4 constexpr int *p = 0;
5 // expected-error@+1 {{must be initialized by a constant expression}}
6 constexpr int *k = (int *) __builtin_assume_aligned(p, 16, n = 5);
8 constexpr void *l = __builtin_assume_aligned(p, 16);
10 // expected-error@+2 {{must be initialized by a constant expression}}
11 // expected-note@+1 {{cast from 'void *' is not allowed in a constant expression}}
12 constexpr int *c = (int *) __builtin_assume_aligned(p, 16);
14 // expected-error@+2 {{must be initialized by a constant expression}}
15 // expected-note@+1 {{alignment of the base pointee object (4 bytes) is less than the asserted 16 bytes}}
16 constexpr void *m = __builtin_assume_aligned(&n, 16);
18 // expected-error@+2 {{must be initialized by a constant expression}}
19 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (-2 bytes) is not a multiple of the asserted 4 bytes}}
20 constexpr void *q1 = __builtin_assume_aligned(&n, 4, 2);
21 // expected-error@+2 {{must be initialized by a constant expression}}
22 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 4 bytes}}
23 constexpr void *q2 = __builtin_assume_aligned(&n, 4, -2);
24 constexpr void *q3 = __builtin_assume_aligned(&n, 4, 4);
25 constexpr void *q4 = __builtin_assume_aligned(&n, 4, -4);
27 static char ar1[6];
28 // expected-error@+2 {{must be initialized by a constant expression}}
29 // expected-note@+1 {{alignment of the base pointee object (1 byte) is less than the asserted 16 bytes}}
30 constexpr void *r1 = __builtin_assume_aligned(&ar1[2], 16);
32 static char ar2[6] __attribute__((aligned(32)));
33 // expected-error@+2 {{must be initialized by a constant expression}}
34 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (2 bytes) is not a multiple of the asserted 16 bytes}}
35 constexpr void *r2 = __builtin_assume_aligned(&ar2[2], 16);
36 constexpr void *r3 = __builtin_assume_aligned(&ar2[2], 16, 2);
37 // expected-error@+2 {{must be initialized by a constant expression}}
38 // expected-note@+1 {{offset of the aligned pointer from the base pointee object (1 byte) is not a multiple of the asserted 16 bytes}}
39 constexpr void *r4 = __builtin_assume_aligned(&ar2[2], 16, 1);
41 constexpr int* x = __builtin_constant_p((int*)0xFF) ? (int*)0xFF : (int*)0xFF;
42 // expected-error@+2 {{must be initialized by a constant expression}}
43 // expected-note@+1 {{value of the aligned pointer (255) is not a multiple of the asserted 32 bytes}}
44 constexpr void *s1 = __builtin_assume_aligned(x, 32);
45 // expected-error@+2 {{must be initialized by a constant expression}}
46 // expected-note@+1 {{value of the aligned pointer (250) is not a multiple of the asserted 32 bytes}}
47 constexpr void *s2 = __builtin_assume_aligned(x, 32, 5);
48 constexpr void *s3 = __builtin_assume_aligned(x, 32, -1);