summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/plugin/diagnostic-path-format-inline-events-2.c
blob: c2bfabec9101216669d7e893eb444f2c9e5bfde6 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* { dg-do compile } */
/* { dg-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */

/* Verify that 'inline-events' copes gracefully with events with an
   unknown location.  */

#include <stdlib.h>

extern void missing_location ();

void *wrapped_malloc (size_t size)
{
  return malloc (size);
}

void wrapped_free (void *ptr)
{
  free (ptr); /* { dg-warning "double-free of 'ptr' \\\[CWE-415\\]" } */
  /* { dg-begin-multiline-output "" }
   free (ptr);
   ^~~~~~~~~~
  'test': events 1-2
    |
    | {
    | ^
    | |
    | (1) entering 'test'
    |   boxed_int *obj = make_boxed_int (i);
    |                    ~~~~~~~~~~~~~~~~~~
    |                    |
    |                    (2) calling 'make_boxed_int'
    |
    +--> 'make_boxed_int': events 3-4
           |
           | {
           | ^
           | |
           | (3) entering 'make_boxed_int'
           |   boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
           |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           |                                    |
           |                                    (4) calling 'wrapped_malloc'
           |
           +--> 'wrapped_malloc': events 5-6
                  |
                  | {
                  | ^
                  | |
                  | (5) entering 'wrapped_malloc'
                  |   return malloc (size);
                  |          ~~~~~~~~~~~~~
                  |          |
                  |          (6) calling 'malloc'
                  |
    <-------------+
    |
  'test': event 7
    |
    |   free_boxed_int (obj);
    |   ^~~~~~~~~~~~~~~~~~~~
    |   |
    |   (7) calling 'free_boxed_int'
    |
    +--> 'free_boxed_int': events 8-9
           |
           | {
           | ^
           | |
           | (8) entering 'free_boxed_int'
           |   wrapped_free (bi);
           |   ~~~~~~~~~~~~~~~~~
           |   |
           |   (9) calling 'wrapped_free'
           |
           +--> 'wrapped_free': events 10-11
                  |
                  | {
                  | ^
                  | |
                  | (10) entering 'wrapped_free'
                  |   free (ptr);
                  |   ~~~~~~~~~~
                  |   |
                  |   (11) calling 'free'
                  |
    <-------------+
    |
  'test': event 12
    |
    |cc1:
    | (12): calling 'missing_location'
    |
  'test': event 13
    |
    |   free_boxed_int (obj);
    |   ^~~~~~~~~~~~~~~~~~~~
    |   |
    |   (13) calling 'free_boxed_int'
    |
    +--> 'free_boxed_int': events 14-15
           |
           | {
           | ^
           | |
           | (14) entering 'free_boxed_int'
           |   wrapped_free (bi);
           |   ~~~~~~~~~~~~~~~~~
           |   |
           |   (15) calling 'wrapped_free'
           |
           +--> 'wrapped_free': events 16-17
                  |
                  | {
                  | ^
                  | |
                  | (16) entering 'wrapped_free'
                  |   free (ptr);
                  |   ~~~~~~~~~~
                  |   |
                  |   (17) calling 'free'
                  |
     { dg-end-multiline-output "" } */
}

typedef struct boxed_int
{
  int i;
} boxed_int;

boxed_int *
make_boxed_int (int i)
{
  boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int));
  result->i = i;
  return result;
}

void
free_boxed_int (boxed_int *bi)
{
  wrapped_free (bi);
}

void test (int i)
{
  boxed_int *obj = make_boxed_int (i);

  free_boxed_int (obj);

  missing_location ();

  free_boxed_int (obj);
}