| 1 |
// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s |
| 2 |
// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter |
| 3 |
|
| 4 |
|
| 5 |
int test1(int *a) { |
| 6 |
__builtin_assume_dereferenceable(a, 32); |
| 7 |
return a[0]; |
| 8 |
} |
| 9 |
|
| 10 |
int test2(int *a) { |
| 11 |
__builtin_assume_dereferenceable(a, 32ull); |
| 12 |
return a[0]; |
| 13 |
} |
| 14 |
|
| 15 |
int test3(int *a) { |
| 16 |
__builtin_assume_dereferenceable(a, 32u); |
| 17 |
return a[0]; |
| 18 |
} |
| 19 |
|
| 20 |
int test4(int *a, unsigned size) { |
| 21 |
__builtin_assume_dereferenceable(a, size); |
| 22 |
return a[0]; |
| 23 |
} |
| 24 |
|
| 25 |
int test5(int *a, unsigned long long size) { |
| 26 |
__builtin_assume_dereferenceable(a, size); |
| 27 |
return a[0]; |
| 28 |
} |
| 29 |
|
| 30 |
int test6(float a) { |
| 31 |
__builtin_assume_dereferenceable(a, 2); // expected-error {{cannot initialize a parameter of type 'const void *' with an lvalue of type 'float'}} |
| 32 |
return 0;; |
| 33 |
} |
| 34 |
|
| 35 |
int test7(int *a) { |
| 36 |
__builtin_assume_dereferenceable(a, 32, 1); // expected-error {{too many arguments to function call, expected 2, have 3}} |
| 37 |
return a[0]; |
| 38 |
} |
| 39 |
|
| 40 |
int test8(int *a) { |
| 41 |
__builtin_assume_dereferenceable(a); // expected-error {{too few arguments to function call, expected 2, have 1}} |
| 42 |
return a[0]; |
| 43 |
} |
| 44 |
|
| 45 |
int test9(int *a) { |
| 46 |
a[0] = __builtin_assume_dereferenceable(a, 32); // expected-error {{assigning to 'int' from incompatible type 'void'}} |
| 47 |
return a[0]; |
| 48 |
} |
| 49 |
|
| 50 |
constexpr int *p = 0; |
| 51 |
constexpr void *l = __builtin_assume_dereferenceable(p, 4); // expected-error {{cannot initialize a variable of type 'void *const' with an rvalue of type 'void'}} |
| 52 |
|
| 53 |
void *foo() { |
| 54 |
return l; |
| 55 |
} |
| 56 |
|
| 57 |
int test10(int *a) { |
| 58 |
__builtin_assume_dereferenceable(a, a); // expected-error {{cannot initialize a parameter of type '__size_t' (aka 'unsigned long') with an lvalue of type 'int *'}} |
| 59 |
return a[0]; |
| 60 |
} |