libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wfree-nonheap-object-4.c
blobe459b247d23d9d366b3081baba828a9dbf34a68c
1 /* PR middle-end/98664 - inconsistent --Wfree-nonheap-object for inlined
2 calls to system headers
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
6 # 7 "Wfree-nonheap-object-4.h" 1 3
8 struct A
10 void *p;
13 static void f0 (struct A *p, void *q) { p->p = q; }
14 static void f1 (struct A *p, void *q) { f0 (p, q); }
15 static void f2 (struct A *p, void *q) { f1 (p, q); }
17 static void g0 (struct A *p)
19 __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" }
22 static void g1 (struct A *p) { g0 (p); }
23 static void g2 (struct A *p) { g1 (p); }
25 # 26 "Wfree-nonheap-object-4.c"
27 #define NOIPA __attribute__ ((noipa))
29 extern int array[]; // { dg-message "declared here" "note on line 29" }
31 /* Verify the warning is issued even for calls in a system header inlined
32 into a function outside the header. */
34 NOIPA void warn_g0 (struct A *p)
36 int *q = array + 1;
38 f0 (p, q);
39 g0 (p);
42 // { dg-message "inlined from 'warn_g0'" "note on line 42" { target *-*-* } 0 }
45 /* Also verify the warning can be suppressed. */
47 NOIPA void nowarn_g0 (struct A *p)
49 int *q = array + 2;
51 f0 (p, q);
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
55 g0 (p);
56 #pragma GCC diagnostic pop
60 NOIPA void warn_g1 (struct A *p)
62 int *q = array + 3;
64 f1 (p, q);
65 g1 (p);
68 // { dg-message "inlined from 'g1'" "note on line 68" { target *-*-* } 0 }
69 // { dg-message "inlined from 'warn_g1'" "note on line 69" { target *-*-* } 0 }
72 NOIPA void nowarn_g1 (struct A *p)
74 int *q = array + 4;
76 f1 (p, q);
78 #pragma GCC diagnostic push
79 #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
80 g1 (p);
81 #pragma GCC diagnostic pop
85 NOIPA void warn_g2 (struct A *p)
87 int *q = array + 5;
89 f2 (p, q);
90 g2 (p);
93 // { dg-message "inlined from 'g2'" "note on line 93" { target *-*-* } 0 }
94 // { dg-message "inlined from 'warn_g2'" "note on line 94" { target *-*-* } 0 }
97 NOIPA void nowarn_g2 (struct A *p)
99 int *q = array + 6;
101 f2 (p, q);
103 #pragma GCC diagnostic push
104 #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
105 g2 (p);
106 #pragma GCC diagnostic pop