| 1 |
/* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ |
| 2 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib free" { ! hostedlib } } */ |
| 3 |
/* { dg-enable-nn-line-numbers "" } */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
extern int some_condition (); |
| 8 |
extern void do_stuff (int); |
| 9 |
|
| 10 |
void |
| 11 |
may_call_free (void *victim) |
| 12 |
{ |
| 13 |
if (some_condition ()) |
| 14 |
return; |
| 15 |
|
| 16 |
free (victim); /* { dg-warning "double-'free' of 'victim'" } */ |
| 17 |
} |
| 18 |
|
| 19 |
void test (void *ptr) |
| 20 |
{ |
| 21 |
do_stuff (1); |
| 22 |
|
| 23 |
may_call_free (ptr); |
| 24 |
|
| 25 |
do_stuff (2); |
| 26 |
|
| 27 |
may_call_free (ptr); |
| 28 |
|
| 29 |
do_stuff (3); |
| 30 |
} |
| 31 |
|
| 32 |
/* { dg-begin-multiline-output "" } |
| 33 |
NN | free (victim); |
| 34 |
| ^~~~~~~~~~~~~ |
| 35 |
'test': events 1-2 |
| 36 |
| |
| 37 |
| NN | void test (void *ptr) |
| 38 |
| | ^~~~ |
| 39 |
| | | |
| 40 |
| | (1) entry to 'test' |
| 41 |
|...... |
| 42 |
| NN | may_call_free (ptr); |
| 43 |
| | ~~~~~~~~~~~~~~~~~~~ |
| 44 |
| | | |
| 45 |
| | (2) calling 'may_call_free' from 'test' |
| 46 |
| |
| 47 |
+--> 'may_call_free': events 3-6 |
| 48 |
| |
| 49 |
| NN | may_call_free (void *victim) |
| 50 |
| | ^~~~~~~~~~~~~ |
| 51 |
| | | |
| 52 |
| | (3) entry to 'may_call_free' |
| 53 |
| NN | { |
| 54 |
| NN | if (some_condition ()) |
| 55 |
| | ~ |
| 56 |
| | | |
| 57 |
| | (4) following 'false' branch... |
| 58 |
|...... |
| 59 |
| NN | free (victim); |
| 60 |
| | ~~~~~~~~~~~~~ |
| 61 |
| | | |
| 62 |
| | (5) ...to here |
| 63 |
| | (6) first 'free' here |
| 64 |
| |
| 65 |
<------+ |
| 66 |
| |
| 67 |
'test': events 7-8 |
| 68 |
| |
| 69 |
| NN | may_call_free (ptr); |
| 70 |
| | ^~~~~~~~~~~~~~~~~~~ |
| 71 |
| | | |
| 72 |
| | (7) returning to 'test' from 'may_call_free' |
| 73 |
|...... |
| 74 |
| NN | may_call_free (ptr); |
| 75 |
| | ~~~~~~~~~~~~~~~~~~~ |
| 76 |
| | | |
| 77 |
| | (8) passing freed pointer 'ptr' in call to 'may_call_free' from 'test' |
| 78 |
| |
| 79 |
+--> 'may_call_free': events 9-12 |
| 80 |
| |
| 81 |
| NN | may_call_free (void *victim) |
| 82 |
| | ^~~~~~~~~~~~~ |
| 83 |
| | | |
| 84 |
| | (9) entry to 'may_call_free' |
| 85 |
| NN | { |
| 86 |
| NN | if (some_condition ()) |
| 87 |
| | ~ |
| 88 |
| | | |
| 89 |
| | (10) following 'false' branch... |
| 90 |
|...... |
| 91 |
| NN | free (victim); |
| 92 |
| | ~~~~~~~~~~~~~ |
| 93 |
| | | |
| 94 |
| | (11) ...to here |
| 95 |
| | (12) second 'free' here; first 'free' was at (6) |
| 96 |
| |
| 97 |
{ dg-end-multiline-output "" { target c } } */ |
| 98 |
/* { dg-begin-multiline-output "" } |
| 99 |
NN | free (victim); |
| 100 |
| ~~~~~^~~~~~~~ |
| 101 |
'void test(void*)': events 1-2 |
| 102 |
| |
| 103 |
| NN | void test (void *ptr) |
| 104 |
| | ^~~~ |
| 105 |
| | | |
| 106 |
| | (1) entry to 'test' |
| 107 |
|...... |
| 108 |
| NN | may_call_free (ptr); |
| 109 |
| | ~~~~~~~~~~~~~~~~~~~ |
| 110 |
| | | |
| 111 |
| | (2) calling 'may_call_free' from 'test' |
| 112 |
| |
| 113 |
+--> 'void may_call_free(void*)': events 3-6 |
| 114 |
| |
| 115 |
| NN | may_call_free (void *victim) |
| 116 |
| | ^~~~~~~~~~~~~ |
| 117 |
| | | |
| 118 |
| | (3) entry to 'may_call_free' |
| 119 |
| NN | { |
| 120 |
| NN | if (some_condition ()) |
| 121 |
| | ~~ |
| 122 |
| | | |
| 123 |
| | (4) following 'false' branch... |
| 124 |
|...... |
| 125 |
| NN | free (victim); |
| 126 |
| | ~~~~~~~~~~~~~ |
| 127 |
| | | |
| 128 |
| | (5) ...to here |
| 129 |
| | (6) first 'free' here |
| 130 |
| |
| 131 |
<------+ |
| 132 |
| |
| 133 |
'void test(void*)': events 7-8 |
| 134 |
| |
| 135 |
| NN | may_call_free (ptr); |
| 136 |
| | ~~~~~~~~~~~~~~^~~~~ |
| 137 |
| | | |
| 138 |
| | (7) returning to 'test' from 'may_call_free' |
| 139 |
|...... |
| 140 |
| NN | may_call_free (ptr); |
| 141 |
| | ~~~~~~~~~~~~~~~~~~~ |
| 142 |
| | | |
| 143 |
| | (8) passing freed pointer 'ptr' in call to 'may_call_free' from 'test' |
| 144 |
| |
| 145 |
+--> 'void may_call_free(void*)': events 9-12 |
| 146 |
| |
| 147 |
| NN | may_call_free (void *victim) |
| 148 |
| | ^~~~~~~~~~~~~ |
| 149 |
| | | |
| 150 |
| | (9) entry to 'may_call_free' |
| 151 |
| NN | { |
| 152 |
| NN | if (some_condition ()) |
| 153 |
| | ~~ |
| 154 |
| | | |
| 155 |
| | (10) following 'false' branch... |
| 156 |
|...... |
| 157 |
| NN | free (victim); |
| 158 |
| | ~~~~~~~~~~~~~ |
| 159 |
| | | |
| 160 |
| | (11) ...to here |
| 161 |
| | (12) second 'free' here; first 'free' was at (6) |
| 162 |
| |
| 163 |
{ dg-end-multiline-output "" { target c++ } } */ |