| 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 |
| 5 |
|
| 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. |
| 8 |
|
| 9 |
int test1(int *a) { |
| 10 |
a = __builtin_assume_aligned(a, 32, 0ull); |
| 11 |
return a[0]; |
| 12 |
} |
| 13 |
|
| 14 |
int test2(int *a) { |
| 15 |
a = __builtin_assume_aligned(a, 32, 0); |
| 16 |
return a[0]; |
| 17 |
} |
| 18 |
|
| 19 |
int test3(int *a) { |
| 20 |
a = __builtin_assume_aligned(a, 32); |
| 21 |
return a[0]; |
| 22 |
} |
| 23 |
|
| 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]; |
| 27 |
} |
| 28 |
|
| 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]; |
| 32 |
} |
| 33 |
|
| 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]; |
| 37 |
} |
| 38 |
|
| 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]; |
| 42 |
} |
| 43 |
|
| 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]; |
| 47 |
} |
| 48 |
|
| 49 |
int test9(int *a) { |
| 50 |
a = __builtin_assume_aligned(a, 1ULL << 31); // no-warning |
| 51 |
return a[0]; |
| 52 |
} |
| 53 |
|
| 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]; |
| 58 |
} |
| 59 |
|
| 60 |
int test11(int *a) { |
| 61 |
a = __builtin_assume_aligned(a, 1ULL << 32); // no-warning |
| 62 |
return a[0]; |
| 63 |
} |
| 64 |
|
| 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]; |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 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]; |
| 74 |
} |
| 75 |
|
| 76 |
int test14(int *a, int b) { |
| 77 |
a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{non-pointer argument to '__builtin_assume_aligned' is not allowed}} |
| 78 |
} |
| 79 |
|
| 80 |
int test15(int *b) { |
| 81 |
int arr[3] = {1, 2, 3}; |
| 82 |
b = (int *)__builtin_assume_aligned(arr, 32); |
| 83 |
return b[0]; |
| 84 |
} |
| 85 |
|
| 86 |
int val(int x) { |
| 87 |
return x; |
| 88 |
} |
| 89 |
|
| 90 |
int test16(int *b) { |
| 91 |
b = (int *)__builtin_assume_aligned(val, 32); |
| 92 |
return b[0]; |
| 93 |
} |
| 94 |
|
| 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}} |
| 99 |
|
| 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 |
| 103 |
|
| 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 |
| 106 |
|
| 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}} |