Changeset View
Changeset View
Standalone View
Standalone View
test/Sema/builtin-load-no-speculate-cxx.cpp
- This file was added.
// REQUIRES: arm-registered-target | |||||
// REQUIRES: aarch64-registered-target | |||||
// RUN: %clang_cc1 -triple aarch64 -x c++ -std=c++11 -DENABLE_ERRORS -verify %s | |||||
// RUN: %clang_cc1 -triple armv7a -x c++ -std=c++11 -DENABLE_ERRORS -verify %s | |||||
// RUN: %clang_cc1 -triple aarch64 -x c++ -std=c++11 %s -emit-llvm -o - | |||||
// RUN: %clang_cc1 -triple armv7a -x c++ -std=c++11 %s -emit-llvm -o - | |||||
void test_valid(int *ptr, int *lower, int *upper, int failval, int *cmpptr) { | |||||
__builtin_load_no_speculate(ptr, lower, upper); | |||||
__builtin_load_no_speculate(ptr, lower, upper, failval); | |||||
__builtin_load_no_speculate(ptr, lower, upper, failval, cmpptr); | |||||
} | |||||
void test_null_bounds(int *ptr, int *lower, int *upper, int failval, int *cmpptr) { | |||||
__builtin_load_no_speculate(ptr, lower, 0); | |||||
__builtin_load_no_speculate(ptr, lower, (void*)0); | |||||
#ifdef ENABLE_ERRORS | |||||
__builtin_load_no_speculate(ptr, 0, 0); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
__builtin_load_no_speculate(ptr, (void*)0, (void*)0); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
__builtin_load_no_speculate(ptr, 0, (void*)0); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
__builtin_load_no_speculate(ptr, 0, 0, failval, cmpptr); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
#endif | |||||
__builtin_load_no_speculate(ptr, lower, nullptr); | |||||
__builtin_load_no_speculate(ptr, nullptr, upper); | |||||
#ifdef ENABLE_ERRORS | |||||
__builtin_load_no_speculate(ptr, nullptr, nullptr); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
__builtin_load_no_speculate(ptr, 0, nullptr); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
__builtin_load_no_speculate(ptr, nullptr, (void*)0); // expected-error {{lower and upper bounds arguments to load_no_speculate builtin must not both be null}} | |||||
#endif | |||||
} | |||||
void test_load_type(void *lower, void *upper) { | |||||
char c; | |||||
c = __builtin_load_no_speculate(&c, lower, upper); | |||||
short s; | |||||
s = __builtin_load_no_speculate(&s, lower, upper); | |||||
int i; | |||||
i = __builtin_load_no_speculate(&i, lower, upper); | |||||
long l; | |||||
l = __builtin_load_no_speculate(&l, lower, upper); | |||||
long long ll; | |||||
ll = __builtin_load_no_speculate(&ll, lower, upper); | |||||
int *ip; | |||||
ip = __builtin_load_no_speculate(&ip, lower, upper); | |||||
int (*fp)(int, int); | |||||
fp = __builtin_load_no_speculate(&fp, lower, upper); | |||||
#ifdef ENABLE_ERRORS | |||||
i = __builtin_load_no_speculate(i, lower, upper); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('int' invalid)}} | |||||
float f; | |||||
f = __builtin_load_no_speculate(&f, lower, upper); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('float *' invalid)}} | |||||
struct S { int a; } S; | |||||
S = __builtin_load_no_speculate(&S, lower, upper); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('struct S *' invalid)}} | |||||
union U { int a; } U; | |||||
U = __builtin_load_no_speculate(&U, lower, upper); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('union U *' invalid)}} | |||||
char __attribute__((vector_size(16))) v; | |||||
v = __builtin_load_no_speculate(&v, lower, upper); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('__attribute__((__vector_size__(16 * sizeof(char)))) char *' invalid)}} | |||||
#endif | |||||
} | |||||
void test_bounds_types(void *lower, void *upper, void *cmpptr) { | |||||
int i; | |||||
#ifdef ENABLE_ERRORS | |||||
__builtin_load_no_speculate(&i, 1234, upper); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'int'}} | |||||
__builtin_load_no_speculate(&i, lower, 5678); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'int}} | |||||
__builtin_load_no_speculate(&i, lower, upper, 0, 5678); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'int}} | |||||
__builtin_load_no_speculate(&i, 3.141, upper); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'double'}} | |||||
__builtin_load_no_speculate(&i, lower, 3.141); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'double'}} | |||||
__builtin_load_no_speculate(&i, lower, upper, 0, 3.141); // expected-error {{cannot initialize a parameter of type 'const volatile void *' with an rvalue of type 'double'}} | |||||
#endif | |||||
// The bounds pointers are of type 'void *', the pointers do not have to be | |||||
// compatible with the first arg. | |||||
struct S {}; | |||||
__builtin_load_no_speculate(&i, (short *)lower, (S *)upper, 0, (float *)0); | |||||
__builtin_load_no_speculate(&i, (const int *)lower, upper); | |||||
__builtin_load_no_speculate(&i, (volatile float *)lower, upper); | |||||
__builtin_load_no_speculate(&i, lower, (const volatile char *)upper); | |||||
__builtin_load_no_speculate(&i, lower, upper, 0, (const volatile char *)cmpptr); | |||||
} | |||||
void test_failval_type(void *lower, void *upper) { | |||||
char c; | |||||
int i; | |||||
int *ip; | |||||
int * const cip = 0; | |||||
int * volatile vip; | |||||
char *cp; | |||||
int (*fp)(int); | |||||
// Exactly correct type | |||||
__builtin_load_no_speculate(&i, lower, upper, 0); | |||||
__builtin_load_no_speculate(&i, lower, upper, i); | |||||
// Implicitly convertible type | |||||
__builtin_load_no_speculate(&i, lower, upper, (char)0); | |||||
__builtin_load_no_speculate(&i, lower, upper, 0.0); | |||||
__builtin_load_no_speculate(&ip, lower, upper, cip); | |||||
__builtin_load_no_speculate(&ip, lower, upper, vip); | |||||
#ifdef ENABLE_ERRORS | |||||
__builtin_load_no_speculate(&i, lower, upper, ip); // expected-error {{assigning to 'int' from incompatible type 'int *'; dereference with *}} | |||||
__builtin_load_no_speculate(&ip, lower, upper, i); // expected-error {{assigning to 'int *' from incompatible type 'int'; take the address with &}} | |||||
__builtin_load_no_speculate(&ip, lower, upper, cp); // expected-error {{assigning to 'int *' from incompatible type 'char *'}} | |||||
__builtin_load_no_speculate(&ip, lower, upper, fp); // expected-error {{assigning to 'int *' from incompatible type 'int (*)(int)'}} | |||||
__builtin_load_no_speculate(&fp, lower, upper, ip); // expected-error {{assigning to 'int (*)(int)' from incompatible type 'int *'}} | |||||
#endif | |||||
} | |||||
#ifdef ENABLE_ERRORS | |||||
template<typename T> | |||||
T load(const T *ptr, const T *upper, const T *lower) { | |||||
return __builtin_load_no_speculate(ptr, upper, lower); // expected-error {{argument to load_no_speculate builtin must be a pointer to a pointer or integer ('const S *' invalid)}} | |||||
} | |||||
void test_templates() { | |||||
int ia[5]; | |||||
load(&ia[3], &ia[0], &ia[5]); | |||||
struct S { int a; }; | |||||
S Sa[5]; | |||||
load(&Sa[3], &Sa[0], &Sa[5]); // expected-note {{in instantiation of function template specialization 'load<S>' requested here}} | |||||
} | |||||
#endif | |||||
void test_convert_failval_type() { | |||||
bool foo; | |||||
__builtin_load_no_speculate(&foo, (void *)0x1000, (void *)0x2000, false); | |||||
} |