[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Sema / builtin-assume-aligned.c
bloba5dd7e387181ebbc92b432e911d8a3bb45e95db1
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
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.
7 int test1(int *a) {
8 a = __builtin_assume_aligned(a, 32, 0ull);
9 return a[0];
12 int test2(int *a) {
13 a = __builtin_assume_aligned(a, 32, 0);
14 return a[0];
17 int test3(int *a) {
18 a = __builtin_assume_aligned(a, 32);
19 return a[0];
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];
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];
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];
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];
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];
47 int test9(int *a) {
48 a = __builtin_assume_aligned(a, 1ULL << 31); // no-warning
49 return a[0];
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];
58 int test11(int *a) {
59 a = __builtin_assume_aligned(a, 1ULL << 32); // no-warning
60 return a[0];
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];
67 #endif
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];
74 void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
75 int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
76 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
77 void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(8589934592))); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}
79 int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
80 void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
81 void *test_with_fn_proto(void) __attribute__((assume_aligned(128))); // no-warning
83 void *test_no_fn_proto() __attribute__((assume_aligned(31))); // expected-error {{requested alignment is not a power of 2}}
84 void *test_no_fn_proto() __attribute__((assume_aligned(32, 73))); // no-warning
86 void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
87 void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
88 void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}