analyzer: fixes to side-effects for built-in functions [PR107565]
[official-gcc.git] / gcc / testsuite / gcc.dg / analyzer / pr99716-1.c
blob4fae368f3210ee4b0c1bedcd2394c3f939ac6dee
1 typedef struct FILE FILE;
3 FILE* fopen (const char*, const char*);
4 int fclose (FILE*);
5 int fprintf (FILE *, const char *, ...);
7 #define NULL ((void *)0)
9 void
10 test_1 (void)
12 int i;
14 for (i = 0; i < 2; ++i) {
15 FILE *fp = fopen ("/tmp/test", "w");
16 fprintf (fp, "hello:%s ", "world");
17 fclose (fp); /* { dg-bogus "double 'fclose'" } */
21 void
22 test_2 (void)
24 int i;
26 for (i = 0; i < 2; ++i) {
27 FILE *fp = fopen ("/tmp/test", "w");
28 fprintf (fp, "hello");
30 } /* { dg-warning "leak of FILE 'fp'" "" { xfail *-*-* } } */
31 /* TODO: fails on some targets due to fprintf call being optimized to
32 __builtin_fwrite with a size argument (idx 2) that fails
33 gimple_builtin_call_types_compatible_p, and thus the known_function
34 for __builtin_fwrite not being used (PR middle-end/108988). */
36 FILE *fp3;
38 void
39 test_3 (FILE **fpp)
41 int i;
43 for (i = 0; i < 2; ++i) {
44 *fpp = fopen ("/tmp/test", "w");
45 fprintf (*fpp, "hello");
46 fclose (*fpp); /* { dg-bogus "double 'fclose'" } */
47 *fpp = NULL;