void clang_analyzer_eval(int);
int glob;
typedef struct FILE FILE;
#define EOF -1
int getc(FILE *);
void test_getc(FILE *fp) {
int x;
while ((x = getc(fp)) != EOF) {
clang_analyzer_eval(x > 255); clang_analyzer_eval(x >= 0); }
}
int fgetc(FILE *);
void test_fgets(FILE *fp) {
clang_analyzer_eval(fgetc(fp) < 256); clang_analyzer_eval(fgetc(fp) >= 0); }
typedef typeof(sizeof(int)) size_t;
typedef signed long ssize_t;
ssize_t read(int, void *, size_t);
ssize_t write(int, const void *, size_t);
void test_read_write(int fd, char *buf) {
glob = 1;
ssize_t x = write(fd, buf, 10);
clang_analyzer_eval(glob); if (x >= 0) {
clang_analyzer_eval(x <= 10); ssize_t y = read(fd, &glob, sizeof(glob));
if (y >= 0) {
clang_analyzer_eval(y <= sizeof(glob)); } else {
clang_analyzer_eval(y <= sizeof(glob)); }
} else {
clang_analyzer_eval(x == -1); }
}
size_t fread(void *restrict, size_t, size_t, FILE *restrict);
size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
void test_fread_fwrite(FILE *fp, int *buf) {
size_t x = fwrite(buf, sizeof(int), 10, fp);
clang_analyzer_eval(x <= 10);
size_t y = fread(buf, sizeof(int), 10, fp);
clang_analyzer_eval(y <= 10);
size_t z = fwrite(buf, sizeof(int), y, fp);
clang_analyzer_eval(z <= y); }
void test_fread_uninitialized(void) {
void *ptr;
size_t sz;
size_t nmem;
FILE *fp;
(void)fread(ptr, sz, nmem, fp); }
ssize_t getline(char **restrict, size_t *restrict, FILE *restrict);
ssize_t getdelim(char **restrict, size_t *restrict, int, FILE *restrict);
void test_getline(FILE *fp) {
char *line = 0;
size_t n = 0;
ssize_t len;
while ((len = getline(&line, &n, fp)) != -1) {
clang_analyzer_eval(len == 0); }
}
int isascii(int);
void test_isascii(int x) {
clang_analyzer_eval(isascii(123)); clang_analyzer_eval(isascii(-1)); if (isascii(x)) {
clang_analyzer_eval(x < 128); clang_analyzer_eval(x >= 0); } else {
if (x > 42)
clang_analyzer_eval(x >= 128); else
clang_analyzer_eval(x < 0); }
glob = 1;
isascii('a');
clang_analyzer_eval(glob); }
int islower(int);
void test_islower(int x) {
clang_analyzer_eval(islower('x')); clang_analyzer_eval(islower('X')); if (islower(x))
clang_analyzer_eval(x < 'a'); }
int getchar(void);
void test_getchar(void) {
int x = getchar();
if (x == EOF)
return;
clang_analyzer_eval(x < 0); clang_analyzer_eval(x < 256); }
int isalpha(int);
void test_isalpha(void) {
clang_analyzer_eval(isalpha(']')); clang_analyzer_eval(isalpha('Q')); clang_analyzer_eval(isalpha(128)); }
int isalnum(int);
void test_alnum(void) {
clang_analyzer_eval(isalnum('1')); clang_analyzer_eval(isalnum(')')); }
int isblank(int);
void test_isblank(void) {
clang_analyzer_eval(isblank('\t')); clang_analyzer_eval(isblank(' ')); clang_analyzer_eval(isblank('\n')); }
int ispunct(int);
void test_ispunct(int x) {
clang_analyzer_eval(ispunct(' ')); clang_analyzer_eval(ispunct(-1)); clang_analyzer_eval(ispunct('#')); clang_analyzer_eval(ispunct('_')); if (ispunct(x))
clang_analyzer_eval(x < 127); }
int isupper(int);
void test_isupper(int x) {
if (isupper(x))
clang_analyzer_eval(x < 'A'); }
int isgraph(int);
int isprint(int);
void test_isgraph_isprint(int x) {
char y = x;
if (isgraph(y))
clang_analyzer_eval(isprint(x)); }
int isdigit(int);
void test_mixed_branches(int x) {
if (isdigit(x)) {
clang_analyzer_eval(isgraph(x)); clang_analyzer_eval(isblank(x)); } else if (isascii(x)) {
clang_analyzer_eval(isalnum(x)); clang_analyzer_eval(isprint(x)); }
}
int isspace(int);
void test_isspace(int x) {
if (!isascii(x))
return;
char y = x;
if (y == ' ')
clang_analyzer_eval(isspace(x)); }
int isxdigit(int);
void test_isxdigit(int x) {
if (isxdigit(x) && isupper(x)) {
clang_analyzer_eval(x >= 'A'); clang_analyzer_eval(x <= 'F'); }
}
void test_call_by_pointer(void) {
typedef int (*func)(int);
func f = isascii;
clang_analyzer_eval(f('A')); f = ispunct;
clang_analyzer_eval(f('A')); }
char *getenv(const char *name);
void test_getenv(void) {
clang_analyzer_eval(getenv("FOO") == 0);
}