1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=apiModeling.Errno \
4 // RUN: -analyzer-checker=debug.ExprInspection \
5 // RUN: -analyzer-checker=debug.ErrnoTest \
8 // RUN: %clang_analyze_cc1 -verify %s \
9 // RUN: -analyzer-checker=core \
10 // RUN: -analyzer-checker=apiModeling.Errno \
11 // RUN: -analyzer-checker=debug.ExprInspection \
12 // RUN: -analyzer-checker=debug.ErrnoTest \
16 #include "Inputs/errno_var.h"
19 #include "Inputs/errno_func.h"
22 void clang_analyzer_eval(int);
23 void ErrnoTesterChecker_setErrno(int);
24 int ErrnoTesterChecker_getErrno();
25 int ErrnoTesterChecker_setErrnoIfError();
26 int ErrnoTesterChecker_setErrnoIfErrorRange();
31 // Test if errno is initialized.
32 clang_analyzer_eval(errno
== 0); // expected-warning{{TRUE}}
34 ErrnoTesterChecker_setErrno(1);
35 // Test if errno was recognized and changed.
36 clang_analyzer_eval(errno
== 1); // expected-warning{{TRUE}}
37 clang_analyzer_eval(ErrnoTesterChecker_getErrno() == 1); // expected-warning{{TRUE}}
41 // Test if errno was invalidated.
42 clang_analyzer_eval(errno
); // expected-warning{{UNKNOWN}}
43 clang_analyzer_eval(ErrnoTesterChecker_getErrno()); // expected-warning{{UNKNOWN}}
46 void testRange(int X
) {
48 ErrnoTesterChecker_setErrno(X
);
49 clang_analyzer_eval(errno
> 0); // expected-warning{{TRUE}}
54 if (ErrnoTesterChecker_setErrnoIfError())
55 clang_analyzer_eval(errno
== 11); // expected-warning{{TRUE}}
58 void testIfErrorRange() {
59 if (ErrnoTesterChecker_setErrnoIfErrorRange()) {
60 clang_analyzer_eval(errno
!= 0); // expected-warning{{TRUE}}
61 clang_analyzer_eval(errno
== 1); // expected-warning{{FALSE}} expected-warning{{TRUE}}