1 // RUN: %clang_analyze_cc1 -verify -analyzer-output text %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=apiModeling.Errno \
4 // RUN: -analyzer-checker=debug.ExprInspection \
5 // RUN: -analyzer-checker=debug.ErrnoTest \
6 // RUN: -analyzer-checker=alpha.unix.Errno \
9 // RUN: %clang_analyze_cc1 -verify -analyzer-output text %s \
10 // RUN: -analyzer-checker=core \
11 // RUN: -analyzer-checker=apiModeling.Errno \
12 // RUN: -analyzer-checker=debug.ExprInspection \
13 // RUN: -analyzer-checker=debug.ErrnoTest \
14 // RUN: -analyzer-checker=alpha.unix.Errno \
17 #include "Inputs/errno_var.h"
18 #include "Inputs/system-header-simulator.h"
20 #include "Inputs/errno_var.h"
23 #include "Inputs/errno_func.h"
26 int ErrnoTesterChecker_setErrnoCheckState();
30 void testErrnoCheckUndefRead() {
31 int X
= ErrnoTesterChecker_setErrnoCheckState();
33 X
= ErrnoTesterChecker_setErrnoCheckState(); // expected-note{{Assuming that this function succeeds but sets 'errno' to an unspecified value}}
34 if (X
== 0) { // expected-note{{'X' is equal to 0}}
35 // expected-note@-1{{Taking true branch}}
37 } // expected-warning@-1{{An undefined value may be read from 'errno'}}
38 // expected-note@-2{{An undefined value may be read from 'errno'}}
42 void testErrnoCheckOverwrite() {
43 int X
= ErrnoTesterChecker_setErrnoCheckState();
45 X
= ErrnoTesterChecker_setErrnoCheckState(); // expected-note{{Assuming that this function returns 2. 'errno' should be checked to test for failure}}
46 if (X
== 2) { // expected-note{{'X' is equal to 2}}
47 // expected-note@-1{{Taking true branch}}
48 errno
= 0; // expected-warning{{Value of 'errno' was not checked and is overwritten here}}
49 // expected-note@-1{{Value of 'errno' was not checked and is overwritten here}}
53 void testErrnoCheckOverwriteStdCall() {
54 int X
= ErrnoTesterChecker_setErrnoCheckState();
56 X
= ErrnoTesterChecker_setErrnoCheckState(); // expected-note{{Assuming that this function returns 2. 'errno' should be checked to test for failure}}
57 if (X
== 2) { // expected-note{{'X' is equal to 2}}
58 // expected-note@-1{{Taking true branch}}
59 printf(""); // expected-warning{{Value of 'errno' was not checked and may be overwritten by function 'printf'}}
60 // expected-note@-1{{Value of 'errno' was not checked and may be overwritten by function 'printf'}}