[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / Analysis / simple-stream-checks.c
blob767ffaf53fcbfd16cb843c0835cc870f2cdf65f7
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.SimpleStream -verify %s
3 #include "Inputs/system-header-simulator-for-simple-stream.h"
5 void checkDoubleFClose(int *Data) {
6 FILE *F = fopen("myfile.txt", "w");
7 if (F != 0) {
8 fputs ("fopen example", F);
9 if (!Data)
10 fclose(F);
11 else
12 fputc(*Data, F);
13 fclose(F); // expected-warning {{Closing a previously closed file stream}}
17 int checkLeak(int *Data) {
18 FILE *F = fopen("myfile.txt", "w");
19 if (F != 0) {
20 fputs ("fopen example", F);
23 if (Data) // expected-warning {{Opened file is never closed; potential resource leak}}
24 return *Data;
25 else
26 return 0;
29 void checkLeakFollowedByAssert(int *Data) {
30 FILE *F = fopen("myfile.txt", "w");
31 if (F != 0) {
32 fputs ("fopen example", F);
33 if (!Data)
34 exit(0);
35 fclose(F);
39 void CloseOnlyOnValidFileHandle(void) {
40 FILE *F = fopen("myfile.txt", "w");
41 if (F)
42 fclose(F);
43 int x = 0; // no warning
46 void leakOnEnfOfPath1(int *Data) {
47 FILE *F = fopen("myfile.txt", "w");
48 } // expected-warning {{Opened file is never closed; potential resource leak}}
50 void leakOnEnfOfPath2(int *Data) {
51 FILE *F = fopen("myfile.txt", "w");
52 return; // expected-warning {{Opened file is never closed; potential resource leak}}
55 FILE *leakOnEnfOfPath3(int *Data) {
56 FILE *F = fopen("myfile.txt", "w");
57 return F;
60 void myfclose(FILE *F);
61 void SymbolEscapedThroughFunctionCall(void) {
62 FILE *F = fopen("myfile.txt", "w");
63 myfclose(F);
64 return; // no warning
67 FILE *GlobalF;
68 void SymbolEscapedThroughAssignmentToGlobal(void) {
69 FILE *F = fopen("myfile.txt", "w");
70 GlobalF = F;
71 return; // no warning
74 void SymbolDoesNotEscapeThoughStringAPIs(char *Data) {
75 FILE *F = fopen("myfile.txt", "w");
76 fputc(*Data, F);
77 return; // expected-warning {{Opened file is never closed; potential resource leak}}
80 void passConstPointer(const FILE * F);
81 void testPassConstPointer(void) {
82 FILE *F = fopen("myfile.txt", "w");
83 passConstPointer(F);
84 return; // expected-warning {{Opened file is never closed; potential resource leak}}
87 void testPassToSystemHeaderFunctionIndirectly(void) {
88 FileStruct fs;
89 fs.p = fopen("myfile.txt", "w");
90 fakeSystemHeaderCall(&fs); // invalidates fs, making fs.p unreachable
91 } // no-warning
93 void testOverwrite(void) {
94 FILE *fp = fopen("myfile.txt", "w");
95 fp = 0;
96 } // expected-warning {{Opened file is never closed; potential resource leak}}