File: Wfree-nonheap-object-6.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (49 lines) | stat: -rw-r--r-- 1,543 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Similar to Wfree-nonheap-object-5.c but with attribute artificial:
   verify that warnings for the same call site from distinct callers
   include the correct function names in the inlining stack.
   { dg-do compile }
   { dg-options "-O1 -Wall" } */

struct A
{
  void *p;
};

__attribute__ ((always_inline, artificial))
inline void f0 (struct A *p)
{
  __builtin_free (p->p);      // { dg-warning "\\\[-Wfree-nonheap-object" }
}

// Expect two instances of the text below:
// { dg-regexp "In function 'f0'," "first f0 prefix" { target *-*-* } 0 }
// { dg-regexp "In function 'f0'," "second f0 prefix" { target *-*-* } 0 }

__attribute__ ((always_inline, artificial))
inline void f1 (struct A *p) { f0 (p); }
__attribute__ ((always_inline, artificial))
inline void f2 (struct A *p) { f1 (p); }

extern int array[];
// Also expect two instances of the note:
// { dg-regexp "declared here" "first note for array" { target *-*-* } .-2 }
// { dg-regexp "declared here" "second note for array" { target *-*-* } .-3 }

void foo (struct A *p)
{
  p->p = array + 1;
  f0 (p);
}

// { dg-regexp " +inlined from 'foo' at \[^:\]+Wfree-nonheap-object-6.c:35:\\d+:" "inlined from foo" }


void bar (struct A *p)
{
  p->p = array + 2;
  f2 (p);
}

// { dg-regexp " +inlined from 'f1' at \[^:\]+Wfree-nonheap-object-6.c:23:\\d+," "inlined from f1" }
// { dg-regexp " +inlined from 'f2' at \[^:\]+Wfree-nonheap-object-6.c:25:\\d+," "inlined from f2" }
// { dg-regexp " +inlined from 'bar' at \[^:\]+Wfree-nonheap-object-6.c:44:\\d+:" "inlined from bar" }