Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / Sema / builtin-assume-aligned.c
blob33e85578451529f833de2af5cca5df38de7cc24a
1 // RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -Wno-strict-prototypes -triple x86_64-linux -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -triple i386-freebsd -verify %s
3 // RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -Wno-strict-prototypes -triple x86_64-linux -verify %s -fexperimental-new-constant-interpreter
4 // RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -triple i386-freebsd -verify %s -fexperimental-new-constant-interpreter
6 // __builtin_assume_aligned's second parameter is size_t, which may be 32 bits,
7 // so test differently when size_t is 32 bits and when it is 64 bits.
9 int test1(int *a) {
10 a = __builtin_assume_aligned(a, 32, 0ull);
11 return a[0];
14 int test2(int *a) {
15 a = __builtin_assume_aligned(a, 32, 0);
16 return a[0];
19 int test3(int *a) {
20 a = __builtin_assume_aligned(a, 32);
21 return a[0];
24 int test4(int *a) {
25 a = __builtin_assume_aligned(a, -32); // expected-error {{requested alignment is not a power of 2}}
26 return a[0];
29 int test5(int *a, unsigned *b) {
30 a = __builtin_assume_aligned(a, 32, b); // expected-error {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}}
31 return a[0];
34 int test6(int *a) {
35 a = __builtin_assume_aligned(a, 32, 0, 0); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
36 return a[0];
39 int test7(int *a) {
40 a = __builtin_assume_aligned(a, 31); // expected-error {{requested alignment is not a power of 2}}
41 return a[0];
44 int test8(int *a, int j) {
45 a = __builtin_assume_aligned(a, j); // expected-error {{must be a constant integer}}
46 return a[0];
49 int test9(int *a) {
50 a = __builtin_assume_aligned(a, 1ULL << 31); // no-warning
51 return a[0];
54 #ifdef SIZE_T_64
55 int test10(int *a) {
56 a = __builtin_assume_aligned(a, 1ULL << 63); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
57 return a[0];
60 int test11(int *a) {
61 a = __builtin_assume_aligned(a, 1ULL << 32); // no-warning
62 return a[0];
65 int test12(int *a) {
66 a = __builtin_assume_aligned(a, 1ULL << 33); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
67 return a[0];
69 #endif
71 int test13(int *a) {
72 a = (int *)__builtin_assume_aligned(a, 2 * 2.0); // expected-error {{argument to '__builtin_assume_aligned' must be a constant integer}}
73 return a[0];
76 int test14(int *a, int b) {
77 a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *}}
80 int test15(int *b) {
81 int arr[3] = {1, 2, 3};
82 b = (int *)__builtin_assume_aligned(arr, 32);
83 return b[0];
86 int val(int x) {
87 return x;
90 int test16(int *b) {
91 b = (int *)__builtin_assume_aligned(val, 32);
92 return b[0];
95 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
96 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
97 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
98 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(8589934592))); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
100 int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
101 void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
102 void *test_with_fn_proto(void) __attribute__((assume_aligned(128))); // no-warning
104 void *test_no_fn_proto() __attribute__((assume_aligned(31))); // expected-error {{requested alignment is not a power of 2}}
105 void *test_no_fn_proto() __attribute__((assume_aligned(32, 73))); // no-warning
107 void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
108 void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
109 void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}