1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc
test1(int * a)3*0a6a1f1dSLionel Sambuc int test1(int *a) {
4*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, 0ull);
5*0a6a1f1dSLionel Sambuc return a[0];
6*0a6a1f1dSLionel Sambuc }
7*0a6a1f1dSLionel Sambuc
test2(int * a)8*0a6a1f1dSLionel Sambuc int test2(int *a) {
9*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, 0);
10*0a6a1f1dSLionel Sambuc return a[0];
11*0a6a1f1dSLionel Sambuc }
12*0a6a1f1dSLionel Sambuc
test3(int * a)13*0a6a1f1dSLionel Sambuc int test3(int *a) {
14*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32);
15*0a6a1f1dSLionel Sambuc return a[0];
16*0a6a1f1dSLionel Sambuc }
17*0a6a1f1dSLionel Sambuc
test4(int * a)18*0a6a1f1dSLionel Sambuc int test4(int *a) {
19*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, -32); // expected-error {{requested alignment is not a power of 2}}
20*0a6a1f1dSLionel Sambuc // FIXME: The line below produces {{requested alignment is not a power of 2}}
21*0a6a1f1dSLionel Sambuc // on i386-freebsd, but not on x86_64-linux (for example).
22*0a6a1f1dSLionel Sambuc // a = __builtin_assume_aligned(a, 1ULL << 63);
23*0a6a1f1dSLionel Sambuc return a[0];
24*0a6a1f1dSLionel Sambuc }
25*0a6a1f1dSLionel Sambuc
test5(int * a,unsigned * b)26*0a6a1f1dSLionel Sambuc int test5(int *a, unsigned *b) {
27*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, b); // expected-warning {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}}
28*0a6a1f1dSLionel Sambuc return a[0];
29*0a6a1f1dSLionel Sambuc }
30*0a6a1f1dSLionel Sambuc
test6(int * a)31*0a6a1f1dSLionel Sambuc int test6(int *a) {
32*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 32, 0, 0); // expected-error {{too many arguments to function call, expected at most 3, have 4}}
33*0a6a1f1dSLionel Sambuc return a[0];
34*0a6a1f1dSLionel Sambuc }
35*0a6a1f1dSLionel Sambuc
test7(int * a)36*0a6a1f1dSLionel Sambuc int test7(int *a) {
37*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, 31); // expected-error {{requested alignment is not a power of 2}}
38*0a6a1f1dSLionel Sambuc return a[0];
39*0a6a1f1dSLionel Sambuc }
40*0a6a1f1dSLionel Sambuc
test8(int * a,int j)41*0a6a1f1dSLionel Sambuc int test8(int *a, int j) {
42*0a6a1f1dSLionel Sambuc a = __builtin_assume_aligned(a, j); // expected-error {{must be a constant integer}}
43*0a6a1f1dSLionel Sambuc return a[0];
44*0a6a1f1dSLionel Sambuc }
45*0a6a1f1dSLionel Sambuc
46*0a6a1f1dSLionel Sambuc void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
47*0a6a1f1dSLionel Sambuc int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
48*0a6a1f1dSLionel Sambuc void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
49*0a6a1f1dSLionel Sambuc
50*0a6a1f1dSLionel Sambuc int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to functions and methods}}
51*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning
52*0a6a1f1dSLionel Sambuc void *test_with_fn_proto(void) __attribute__((assume_aligned(128))); // no-warning
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned(31))); // expected-error {{requested alignment is not a power of 2}}
55*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned(32, 73))); // no-warning
56*0a6a1f1dSLionel Sambuc
57*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
58*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}
59*0a6a1f1dSLionel Sambuc void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}
60*0a6a1f1dSLionel Sambuc
61