1 /* { dg-do compile } */ 2 /* { dg-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */ 3 4 /* Verify that 'inline-events' copes gracefully with events with an 5 unknown location. */ 6 7 #include <stdlib.h> 8 9 extern void missing_location (); 10 wrapped_malloc(size_t size)11void *wrapped_malloc (size_t size) 12 { 13 return malloc (size); 14 } 15 wrapped_free(void * ptr)16void wrapped_free (void *ptr) 17 { 18 free (ptr); /* { dg-warning "double-free of 'ptr' \\\[CWE-415\\]" } */ 19 /* { dg-begin-multiline-output "" } 20 free (ptr); 21 ^~~~~~~~~~ 22 'test': events 1-2 23 | 24 | { 25 | ^ 26 | | 27 | (1) entering 'test' 28 | boxed_int *obj = make_boxed_int (i); 29 | ~~~~~~~~~~~~~~~~~~ 30 | | 31 | (2) calling 'make_boxed_int' 32 | 33 +--> 'make_boxed_int': events 3-4 34 | 35 | { 36 | ^ 37 | | 38 | (3) entering 'make_boxed_int' 39 | boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); 40 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41 | | 42 | (4) calling 'wrapped_malloc' 43 | 44 +--> 'wrapped_malloc': events 5-6 45 | 46 | { 47 | ^ 48 | | 49 | (5) entering 'wrapped_malloc' 50 | return malloc (size); 51 | ~~~~~~~~~~~~~ 52 | | 53 | (6) calling 'malloc' 54 | 55 <-------------+ 56 | 57 'test': event 7 58 | 59 | free_boxed_int (obj); 60 | ^~~~~~~~~~~~~~~~~~~~ 61 | | 62 | (7) calling 'free_boxed_int' 63 | 64 +--> 'free_boxed_int': events 8-9 65 | 66 | { 67 | ^ 68 | | 69 | (8) entering 'free_boxed_int' 70 | wrapped_free (bi); 71 | ~~~~~~~~~~~~~~~~~ 72 | | 73 | (9) calling 'wrapped_free' 74 | 75 +--> 'wrapped_free': events 10-11 76 | 77 | { 78 | ^ 79 | | 80 | (10) entering 'wrapped_free' 81 | free (ptr); 82 | ~~~~~~~~~~ 83 | | 84 | (11) calling 'free' 85 | 86 <-------------+ 87 | 88 'test': event 12 89 | 90 |cc1: 91 | (12): calling 'missing_location' 92 | 93 'test': event 13 94 | 95 | free_boxed_int (obj); 96 | ^~~~~~~~~~~~~~~~~~~~ 97 | | 98 | (13) calling 'free_boxed_int' 99 | 100 +--> 'free_boxed_int': events 14-15 101 | 102 | { 103 | ^ 104 | | 105 | (14) entering 'free_boxed_int' 106 | wrapped_free (bi); 107 | ~~~~~~~~~~~~~~~~~ 108 | | 109 | (15) calling 'wrapped_free' 110 | 111 +--> 'wrapped_free': events 16-17 112 | 113 | { 114 | ^ 115 | | 116 | (16) entering 'wrapped_free' 117 | free (ptr); 118 | ~~~~~~~~~~ 119 | | 120 | (17) calling 'free' 121 | 122 { dg-end-multiline-output "" } */ 123 } 124 125 typedef struct boxed_int 126 { 127 int i; 128 } boxed_int; 129 130 boxed_int * make_boxed_int(int i)131make_boxed_int (int i) 132 { 133 boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); 134 result->i = i; 135 return result; 136 } 137 138 void free_boxed_int(boxed_int * bi)139free_boxed_int (boxed_int *bi) 140 { 141 wrapped_free (bi); 142 } 143 test(int i)144void test (int i) 145 { 146 boxed_int *obj = make_boxed_int (i); 147 148 free_boxed_int (obj); 149 150 missing_location (); 151 152 free_boxed_int (obj); 153 } 154 155