]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/c-c++-common/Wuse-after-free-3.c
1 /* Exercise -Wuse-after-free with user-defined deallocators.
3 { dg-options "-O0 -Wall" } */
5 typedef __SIZE_TYPE__
size_t;
8 # define EXTERN_C extern "C"
10 # define EXTERN_C extern
13 #define A(...) __attribute__ ((malloc (__VA_ARGS__)))
15 EXTERN_C
void free (void *);
16 EXTERN_C
void* realloc (void *, size_t);
18 typedef struct List
{ struct List
*next
; } List
;
20 // User-defined allocator/deallocator just like like realloc and free.
21 extern void list_free (List
*);
22 extern List
* list_realloc (size_t, List
*);
23 extern A (list_realloc
, 2) List
* list_realloc (size_t, List
*);
24 extern A (list_free
, 1) List
* list_realloc (size_t, List
*);
30 extern List
*elp
, *elpa
[];
32 void nowarn_list_free (struct List
*lp
)
62 struct List
*next
= lp
->next
;
69 void nowarn_list_free_list (List
*head
)
71 for (List
*p
= head
, *q
; p
; p
= q
)
78 void warn_list_free_list (List
*head
)
81 for (; p
; p
= p
->next
) // { dg-warning "\\\[-Wuse-after-free" }
82 list_free (p
); // { dg-message "call to '\(void \)?list_free\(\\(List\\*\\)\)?'" "note" }