George Burgess IV | e376337 | 2016-12-22 02:50:20 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify |
| 2 | |
| 3 | void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' attribute takes at least 1 argument}} |
| 4 | void *fail2(int a) __attribute__((alloc_size())); //expected-error{{'alloc_size' attribute takes at least 1 argument}} |
| 5 | |
Aaron Ballman | 836684a | 2018-02-25 20:40:06 +0000 | [diff] [blame] | 6 | void *fail3(int a) __attribute__((alloc_size(0))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}} |
| 7 | void *fail4(int a) __attribute__((alloc_size(2))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}} |
George Burgess IV | e376337 | 2016-12-22 02:50:20 +0000 | [diff] [blame] | 8 | |
Aaron Ballman | 836684a | 2018-02-25 20:40:06 +0000 | [diff] [blame] | 9 | void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}} |
| 10 | void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); //expected-error{{'alloc_size' attribute parameter 1 is out of bounds}} |
George Burgess IV | e376337 | 2016-12-22 02:50:20 +0000 | [diff] [blame] | 11 | |
Aaron Ballman | 836684a | 2018-02-25 20:40:06 +0000 | [diff] [blame] | 12 | void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds}} |
| 13 | void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds}} |
George Burgess IV | e376337 | 2016-12-22 02:50:20 +0000 | [diff] [blame] | 14 | |
| 15 | int fail9(int a) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to return values that are pointers}} |
| 16 | |
George Burgess IV | 48badd6 | 2016-12-22 18:48:34 +0000 | [diff] [blame] | 17 | int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}} |
George Burgess IV | e376337 | 2016-12-22 02:50:20 +0000 | [diff] [blame] | 18 | |
| 19 | void *fail11(void *a) __attribute__((alloc_size(1))); //expected-error{{'alloc_size' attribute argument may only refer to a function parameter of integer type}} |
| 20 | |
| 21 | void *fail12(int a) __attribute__((alloc_size("abc"))); //expected-error{{'alloc_size' attribute requires parameter 1 to be an integer constant}} |
| 22 | void *fail12(int a) __attribute__((alloc_size(1, "abc"))); //expected-error{{'alloc_size' attribute requires parameter 2 to be an integer constant}} |
| 23 | void *fail13(int a) __attribute__((alloc_size(1U<<31))); //expected-error{{integer constant expression evaluates to value 2147483648 that cannot be represented in a 32-bit signed integer type}} |
George Burgess IV | 48badd6 | 2016-12-22 18:48:34 +0000 | [diff] [blame] | 24 | |
| 25 | int (*PR31453)(int) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}} |