110 lines · c
1// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -Wno-strict-prototypes -triple x86_64-linux -verify %s2// RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -triple i386-freebsd -verify %s3// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -Wno-strict-prototypes -triple x86_64-linux -verify %s -fexperimental-new-constant-interpreter4// RUN: %clang_cc1 -fsyntax-only -Wno-strict-prototypes -triple i386-freebsd -verify %s -fexperimental-new-constant-interpreter5 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 9int test1(int *a) {10 a = __builtin_assume_aligned(a, 32, 0ull);11 return a[0];12}13 14int test2(int *a) {15 a = __builtin_assume_aligned(a, 32, 0);16 return a[0];17}18 19int test3(int *a) {20 a = __builtin_assume_aligned(a, 32);21 return a[0];22}23 24int 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 29int 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 34int 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 39int 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 44int 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 49int test9(int *a) {50 a = __builtin_assume_aligned(a, 1ULL << 31); // no-warning51 return a[0];52}53 54#ifdef SIZE_T_6455int 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 60int test11(int *a) {61 a = __builtin_assume_aligned(a, 1ULL << 32); // no-warning62 return a[0];63}64 65int 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#endif70 71int 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 76int 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 80int test15(int *b) {81 int arr[3] = {1, 2, 3};82 b = (int *)__builtin_assume_aligned(arr, 32);83 return b[0];84}85 86int val(int x) {87 return x;88}89 90int test16(int *b) {91 b = (int *)__builtin_assume_aligned(val, 32);92 return b[0];93}94 95void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}96int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}97void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning98void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(8589934592))); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}99 100int j __attribute__((assume_aligned(8))); // expected-warning {{'assume_aligned' attribute only applies to Objective-C methods and functions}}101void *test_no_fn_proto() __attribute__((assume_aligned(32))); // no-warning102void *test_with_fn_proto(void) __attribute__((assume_aligned(128))); // no-warning103 104void *test_no_fn_proto() __attribute__((assume_aligned(31))); // expected-error {{requested alignment is not a power of 2}}105void *test_no_fn_proto() __attribute__((assume_aligned(32, 73))); // no-warning106 107void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}108void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}}109void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}}110