xref: /llvm-project/clang/test/Analysis/stream-pedantic.c (revision 09f160c6298255f520b379b88161fbd1c365b308)
1 // RUN: %clang_analyze_cc1 -triple=x86_64-pc-linux-gnu -analyzer-checker=core,unix.Stream,debug.ExprInspection \
2 // RUN:   -analyzer-config unix.Stream:Pedantic=false -verify=nopedantic %s
3 
4 // RUN: %clang_analyze_cc1 -triple=x86_64-pc-linux-gnu -analyzer-checker=core,unix.Stream,debug.ExprInspection \
5 // RUN:   -analyzer-config unix.Stream:Pedantic=true -verify=pedantic %s
6 
7 #include "Inputs/system-header-simulator.h"
8 
9 void clang_analyzer_eval(int);
10 
check_fwrite(void)11 void check_fwrite(void) {
12   char *Buf = "123456789";
13   FILE *Fp = tmpfile();
14   if (!Fp)
15     return;
16   size_t Ret = fwrite(Buf, 1, 10, Fp);
17   clang_analyzer_eval(Ret == 0); // nopedantic-warning {{FALSE}} \
18                                  // pedantic-warning {{FALSE}} \
19                                  // pedantic-warning {{TRUE}}
20   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
21   fclose(Fp);
22 }
23 
check_fputc(void)24 void check_fputc(void) {
25   FILE *Fp = tmpfile();
26   if (!Fp)
27     return;
28   int Ret = fputc('A', Fp);
29   clang_analyzer_eval(Ret == EOF); // nopedantic-warning {{FALSE}} \
30                                    // pedantic-warning {{FALSE}} \
31                                    // pedantic-warning {{TRUE}}
32   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
33   fclose(Fp);
34 }
35 
check_fputs(void)36 void check_fputs(void) {
37   FILE *Fp = tmpfile();
38   if (!Fp)
39     return;
40   int Ret = fputs("ABC", Fp);
41   clang_analyzer_eval(Ret == EOF); // nopedantic-warning {{FALSE}} \
42                                    // pedantic-warning {{FALSE}} \
43                                    // pedantic-warning {{TRUE}}
44   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
45   fclose(Fp);
46 }
47 
check_fprintf(void)48 void check_fprintf(void) {
49   FILE *Fp = tmpfile();
50   if (!Fp)
51     return;
52   int Ret = fprintf(Fp, "ABC");
53   clang_analyzer_eval(Ret < 0); // nopedantic-warning {{FALSE}} \
54                                 // pedantic-warning {{FALSE}} \
55                                 // pedantic-warning {{TRUE}}
56   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
57   fclose(Fp);
58 }
59 
check_fseek(void)60 void check_fseek(void) {
61   FILE *Fp = tmpfile();
62   if (!Fp)
63     return;
64   int Ret = fseek(Fp, 0, 0);
65   clang_analyzer_eval(Ret == -1); // nopedantic-warning {{FALSE}} \
66                                   // pedantic-warning {{FALSE}} \
67                                   // pedantic-warning {{TRUE}}
68   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
69   fclose(Fp);
70 }
71 
check_fseeko(void)72 void check_fseeko(void) {
73   FILE *Fp = tmpfile();
74   if (!Fp)
75     return;
76   int Ret = fseeko(Fp, 0, 0);
77   clang_analyzer_eval(Ret == -1); // nopedantic-warning {{FALSE}} \
78                                   // pedantic-warning {{FALSE}} \
79                                   // pedantic-warning {{TRUE}}
80   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
81   fclose(Fp);
82 }
83 
check_fsetpos(void)84 void check_fsetpos(void) {
85   FILE *Fp = tmpfile();
86   if (!Fp)
87     return;
88   fpos_t Pos;
89   int Ret = fsetpos(Fp, &Pos);
90   clang_analyzer_eval(Ret); // nopedantic-warning {{FALSE}} \
91                             // pedantic-warning {{FALSE}} \
92                             // pedantic-warning {{TRUE}}
93   fputc('A', Fp); // pedantic-warning {{might be 'indeterminate'}}
94   fclose(Fp);
95 }
96