Testsuite: fix analyzer tests on Darwin
[official-gcc.git] / gcc / testsuite / gcc.dg / analyzer / uninit-4.c
blob31c6ae0c611b17c309ab68a3233c90d8a57c517d
1 /* Example of interprocedural detection of an uninitialized field
2 in a heap-allocated struct. */
4 #include <stdlib.h>
5 #include "analyzer-decls.h"
7 struct foo
9 int i;
10 int j;
11 int k;
14 struct foo *__attribute__((noinline))
15 alloc_foo (int a, int b)
17 struct foo *p = malloc (sizeof (struct foo)); /* { dg-message "region created on heap here" } */
18 if (!p)
19 return NULL;
20 p->i = a;
21 p->k = b;
22 return p;
25 void test_access_inited_fields (int x, int y, int z)
27 struct foo *p = alloc_foo (x, z);
28 if (!p)
29 return;
31 __analyzer_eval (p->i == x); /* { dg-warning "TRUE" } */
33 __analyzer_eval (p->k == z); /* { dg-warning "TRUE" } */
35 free (p);
38 void test_stop_after_accessing_uninit (int x, int y, int z)
40 struct foo *p = alloc_foo (x, z);
41 if (!p)
42 return;
44 __analyzer_eval (p->i == x); /* { dg-warning "TRUE" } */
46 __analyzer_eval (p->j == y); /* { dg-warning "use of uninitialized value '\\*p\\.j'" } */
48 __analyzer_dump_path (); /* { dg-bogus "path" } */