Debian Codegraph @

clang/test/Sema/builtin-assume-aligned.c

raw
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
4 // __builtin_assume_aligned's second parameter is size_t, which may be 32 bits,
5 // so test differently when size_t is 32 bits and when it is 64 bits.
6
7 int test1(int *a) {
8 a = __builtin_assume_aligned(a, 32, 0ull);
9 return a[0];
10 }
11
12 int test2(int *a) {
13 a = __builtin_assume_aligned(a, 32, 0);
14 return a[0];
15 }
16
17 int test3(int *a) {
18 a = __builtin_assume_aligned(a, 32);
19 return a[0];
20 }
21
22 int test4(int *a) {
23 a = __builtin_assume_aligned(a, -32); // expected-error {{requested alignment is not a power of 2}}
24 return a[0];
25 }
26
27 int test5(int *a, unsigned *b) {
28 a = __builtin_assume_aligned(a, 32, b); // expected-error {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}}
29 return a[0];
30 }
31
32 int test6(int *a) {
33 a = __builtin_assume_aligned(a, 32, 0, 0); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
34 return a[0];
35 }
36
37 int test7(int *a) {
38 a = __builtin_assume_aligned(a, 31); // expected-error {{requested alignment is not a power of 2}}
39 return a[0];
40 }
41
42 int test8(int *a, int j) {
43 a = __builtin_assume_aligned(a, j); // expected-error {{must be a constant integer}}
44 return a[0];
45 }
46
47 int test9(int *a) {
48 a = __builtin_assume_aligned(a, 1ULL << 31); // no-warning
49 return a[0];
50 }
51
52 #ifdef SIZE_T_64
53 int test10(int *a) {
54 a = __builtin_assume_aligned(a, 1ULL << 63); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
55 return a[0];
56 }
57
58 int test11(int *a) {
59 a = __builtin_assume_aligned(a, 1ULL << 32); // no-warning
60 return a[0];
61 }
62
63 int test12(int *a) {
64 a = __builtin_assume_aligned(a, 1ULL << 33); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
65 return a[0];
66 }
67 #endif
68
69 int test13(int *a) {
70 a = (int *)__builtin_assume_aligned(a, 2 * 2.0); // expected-error {{argument to '__builtin_assume_aligned' must be a constant integer}}
71 return a[0];
72 }
73
74 int test14(int *a, int b) {
75 a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *}}
76 }
77
78 int test15(int *b) {
79 int arr[3] = {1, 2, 3};
80 b = (int *)__builtin_assume_aligned(arr, 32);
81 return b[0];
82 }
83
84 int val(int x) {
85 return x;
86 }
87
88 int test16(int *b) {
89 b = (int *)__builtin_assume_aligned(val, 32);
90 return b[0];
91 }
92
93 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
94 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
95 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
96 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(8589934592))); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
97
98 int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
99 void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
100 void *test_with_fn_proto(void) __attribute__((assume_aligned(128))); // no-warning
101
102 void *test_no_fn_proto() __attribute__((assume_aligned(31))); // expected-error {{requested alignment is not a power of 2}}
103 void *test_no_fn_proto() __attribute__((assume_aligned(32, 73))); // no-warning
104
105 void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
106 void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
107 void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}