61 lines · cpp
1// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s2// RUN: %clang_cc1 -DSIZE_T_64 -fsyntax-only -verify -std=c++11 -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter3 4 5int test1(int *a) {6 __builtin_assume_dereferenceable(a, 32);7 return a[0];8}9 10int test2(int *a) {11 __builtin_assume_dereferenceable(a, 32ull);12 return a[0];13}14 15int test3(int *a) {16 __builtin_assume_dereferenceable(a, 32u);17 return a[0];18}19 20int test4(int *a, unsigned size) {21 __builtin_assume_dereferenceable(a, size);22 return a[0];23}24 25int test5(int *a, unsigned long long size) {26 __builtin_assume_dereferenceable(a, size);27 return a[0];28}29 30int 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 35int 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 40int 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 45int 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 50constexpr int *p = 0;51constexpr void *l = __builtin_assume_dereferenceable(p, 4); // expected-error {{cannot initialize a variable of type 'void *const' with an rvalue of type 'void'}}52 53void *foo() {54 return l;55}56 57int 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}61