#ifdef USE_BUILTINS
# define BUILTIN(f) __builtin_ ## f
#else
# define BUILTIN(f) f
#endif
typedef __SIZE_TYPE__ size_t;
typedef __WCHAR_TYPE__ wchar_t;
void clang_analyzer_eval(int);
#define wmemcpy BUILTIN(wmemcpy)
wchar_t *wmemcpy(wchar_t *restrict s1, const wchar_t *restrict s2, size_t n);
void wmemcpy0 (void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[4] = {0};
wmemcpy(dst, src, 4);
clang_analyzer_eval(wmemcpy(dst, src, 4) == dst);
clang_analyzer_eval(dst[0] != 0); }
void wmemcpy1 (void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[10];
wmemcpy(dst, src, 5); }
void wmemcpy2 (void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[1];
wmemcpy(dst, src, 4); }
void wmemcpy3 (void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[3];
wmemcpy(dst+1, src+2, 2); }
void wmemcpy4 (void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[10];
wmemcpy(dst+2, src+2, 3); }
void wmemcpy5(void) {
wchar_t src[] = {1, 2, 3, 4};
wchar_t dst[3];
wmemcpy(dst + 2, src + 2, 2); }
void wmemcpy6(void) {
wchar_t a[4] = {0};
wmemcpy(a, a, 2); }
void wmemcpy7(void) {
wchar_t a[4] = {0};
wmemcpy(a+2, a+1, 2); }
void wmemcpy8(void) {
wchar_t a[4] = {0};
wmemcpy(a+1, a+2, 2); }
void wmemcpy9(void) {
wchar_t a[4] = {0};
wmemcpy(a+2, a+1, 1); wmemcpy(a+1, a+2, 1); }
void wmemcpy10(void) {
wchar_t a[4] = {0};
wmemcpy(0, a, 1); }
void wmemcpy11(void) {
wchar_t a[4] = {0};
wmemcpy(a, 0, 1); }
void wmemcpy12(void) {
wchar_t a[4] = {0};
wmemcpy(0, a, 0); }
void wmemcpy13(void) {
wchar_t a[4] = {0};
wmemcpy(a, 0, 0); }
void wmemcpy_unknown_size (size_t n) {
wchar_t a[4], b[4] = {1};
clang_analyzer_eval(wmemcpy(a, b, n) == a); }
void wmemcpy_unknown_size_warn (size_t n) {
wchar_t a[4];
void *result = wmemcpy(a, 0, n); clang_analyzer_eval(result == a); }
#define wcslen BUILTIN(wcslen)
size_t wcslen(const wchar_t *s);
void wcslen_constant0(void) {
clang_analyzer_eval(wcslen(L"123") == 3); }
void wcslen_constant1(void) {
const wchar_t *a = L"123";
clang_analyzer_eval(wcslen(a) == 3); }
void wcslen_constant2(wchar_t x) {
wchar_t a[] = L"123";
clang_analyzer_eval(wcslen(a) == 3);
a[0] = x;
clang_analyzer_eval(wcslen(a) == 3); }
size_t wcslen_null(void) {
return wcslen(0); }
size_t wcslen_fn(void) {
return wcslen((wchar_t*)&wcslen_fn); }
size_t wcslen_nonloc(void) {
label:
return wcslen((wchar_t*)&&label); }
void wcslen_subregion(void) {
struct two_strings { wchar_t a[2], b[2]; };
extern void use_two_strings(struct two_strings *);
struct two_strings z;
use_two_strings(&z);
size_t a = wcslen(z.a);
z.b[0] = 5;
size_t b = wcslen(z.a);
if (a == 0)
clang_analyzer_eval(b == 0);
use_two_strings(&z);
size_t c = wcslen(z.a);
if (a == 0)
clang_analyzer_eval(c == 0); }
extern void use_string(wchar_t *);
void wcslen_argument(wchar_t *x) {
size_t a = wcslen(x);
size_t b = wcslen(x);
if (a == 0)
clang_analyzer_eval(b == 0);
use_string(x);
size_t c = wcslen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
extern wchar_t global_str[];
void wcslen_global(void) {
size_t a = wcslen(global_str);
size_t b = wcslen(global_str);
if (a == 0) {
clang_analyzer_eval(b == 0); clang_analyzer_eval(wcslen(global_str) == 0); }
use_string(0);
size_t c = wcslen(global_str);
if (a == 0)
clang_analyzer_eval(c == 0); }
void wcslen_indirect(wchar_t *x) {
size_t a = wcslen(x);
wchar_t *p = x;
wchar_t **p2 = &p;
size_t b = wcslen(x);
if (a == 0)
clang_analyzer_eval(b == 0);
extern void use_string_ptr(wchar_t*const*);
use_string_ptr(p2);
size_t c = wcslen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
void wcslen_indirect2(wchar_t *x) {
size_t a = wcslen(x);
wchar_t *p = x;
wchar_t **p2 = &p;
extern void use_string_ptr2(wchar_t**);
use_string_ptr2(p2);
size_t c = wcslen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
void wcslen_liveness(const wchar_t *x) {
if (wcslen(x) < 5)
return;
clang_analyzer_eval(wcslen(x) < 5); }
size_t wcslenWrapper(const wchar_t *str) {
return wcslen(str);
}
extern void invalidate(wchar_t *s);
void testwcslenCallee(void) {
wchar_t str[42];
invalidate(str);
size_t lenBefore = wcslenWrapper(str);
invalidate(str);
size_t lenAfter = wcslenWrapper(str);
clang_analyzer_eval(lenBefore == lenAfter); }
size_t wcsnlen(const wchar_t *s, size_t maxlen);
void wcsnlen_constant0(void) {
clang_analyzer_eval(wcsnlen(L"123", 10) == 3); }
void wcsnlen_constant1(void) {
const wchar_t *a = L"123";
clang_analyzer_eval(wcsnlen(a, 10) == 3); }
void wcsnlen_constant2(char x) {
wchar_t a[] = L"123";
clang_analyzer_eval(wcsnlen(a, 10) == 3); a[0] = x;
clang_analyzer_eval(wcsnlen(a, 10) == 3); }
void wcsnlen_constant4(void) {
clang_analyzer_eval(wcsnlen(L"123456", 3) == 3); }
void wcsnlen_constant5(void) {
const wchar_t *a = L"123456";
clang_analyzer_eval(wcsnlen(a, 3) == 3); }
void wcsnlen_constant6(char x) {
wchar_t a[] = L"123456";
clang_analyzer_eval(wcsnlen(a, 3) == 3); a[0] = x;
clang_analyzer_eval(wcsnlen(a, 3) == 3); }
size_t wcsnlen_null(void) {
return wcsnlen(0, 3); }
size_t wcsnlen_fn(void) {
return wcsnlen((wchar_t*)&wcsnlen_fn, 3); }
size_t wcsnlen_nonloc(void) {
label:
return wcsnlen((wchar_t*)&&label, 3); }
void wcsnlen_zero(void) {
clang_analyzer_eval(wcsnlen(L"abc", 0) == 0); clang_analyzer_eval(wcsnlen(0, 0) == 0); }
size_t wcsnlen_compound_literal(void) {
return wcsnlen((wchar_t[]) { 'a', 'b', 0 }, 1);
}
size_t wcsnlen_unknown_limit(float f) {
return wcsnlen(L"abc", (int)f);
}
void wcsnlen_is_not_wcslen(wchar_t *x) {
clang_analyzer_eval(wcsnlen(x, 10) == wcslen(x)); }
void wcsnlen_at_limit(wchar_t *x) {
size_t len = wcsnlen(x, 10);
clang_analyzer_eval(len <= 10); clang_analyzer_eval(len == 10); clang_analyzer_eval(len < 10); }
void wcsnlen_at_actual(size_t limit) {
size_t len = wcsnlen(L"abc", limit);
clang_analyzer_eval(len <= 3); if (limit == 0) {
clang_analyzer_eval(len == 0); } else {
clang_analyzer_eval(len == 3); clang_analyzer_eval(len < 3); }
}
static const wchar_t w_str[] = L"Hello world";
void wmemcpy_sizeof(void) {
wchar_t a[32];
wmemcpy(a, w_str, sizeof(w_str) / sizeof(w_str[0]));
wmemcpy(a, w_str, (sizeof(w_str) / sizeof(w_str[0])) + 1); }
void wmemcpy_wcslen(void) {
wchar_t a[32];
const wchar_t w_str1[] = L"Hello world";
wmemcpy(a, w_str1, wcslen(w_str1) + 1);
wmemcpy(a, w_str1, wcslen(w_str1) + 2); }