1 /* Make sure that the 3 types of warnings generated from tree-ssa-uninit.cc have
2 proper virtual locations and so can be controlled by pragmas when they appear
3 in macros. */
4
5 /* { dg-do compile } */
6 /* { dg-options "-Wuninitialized -Wmaybe-uninitialized" } */
7
8 /* 1. Check maybe_warn_read_write_only(). */
9 #define DEREF1(p) (*p) /* { dg-warning {may be used uninitialized} } */
10 __attribute__ ((access (write_only, 1)))
11 int f1 (int* x) /* { dg-note {accessing argument 1} } */
12 {
13 return DEREF1 (x); /* { dg-note {in expansion of macro 'DEREF1'} } */
14 }
15
16 #define DEREF2(p) (*p) /* { dg-bogus {may be used uninitialized} } */
17 #pragma GCC diagnostic push
18 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
19 __attribute__ ((access (write_only, 1)))
20 int f2 (int* x) /* { dg-bogus {accessing argument 1} } */
21 {
22 return DEREF2 (x); /* { dg-bogus {in expansion of macro 'DEREF1'} } */
23 }
24 #pragma GCC diagnostic pop
25
26 /* 2. Check warn_uninit(). */
27 int g;
28 #define SET3(a, b) ((a) = (b)) /* { dg-warning {'x' is used uninitialized} } */
29 void f3 ()
30 {
31 int x; /* { dg-note {'x' was declared here} } */
32 SET3 (g, x); /* { dg-note {in expansion of macro 'SET3'} } */
33 }
34
35 #define SET4(a, b) ((a) = (b)) /* { dg-bogus {'x' is used uninitialized} } */
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wuninitialized"
38 void f4 ()
39 {
40 int x; /* { dg-bogus {'x' was declared here} } */
41 SET4 (g, x); /* { dg-bogus {in expansion of macro 'SET3'} } */
42 }
43 #pragma GCC diagnostic pop
44
45 /* 3. Check maybe_warn_operand(). */
46 #define CALL5(func, arg) ((func) (arg)) /* { dg-warning {'c' may be used uninitialized} } */
47 void f5a (const char *); /* { dg-note {by argument 1} } */
48 void f5b ()
49 {
50 char c; /* { dg-note {'c' declared here} } */
51 CALL5 (f5a, &c); /* { dg-note {in expansion of macro 'CALL5'} } */
52 }
53
54 #define CALL6(func, arg) ((func) (arg)) /* { dg-bogus {'c' may be used uninitialized} } */
55 #pragma GCC diagnostic push
56 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
57 void f6a (const char *); /* { dg-bogus {by argument 1} } */
58 void f6b ()
59 {
60 char c; /* { dg-bogus {'c' declared here} } */
61 CALL6 (f6a, &c); /* { dg-bogus {in expansion of macro 'CALL6'} } */
62 }
63 #pragma GCC diagnostic pop