1 /* { dg-require-effective-target alloca } */
5 typedef void *(*allocator_t
) (size_t);
6 typedef void (*deallocator_t
) (void *);
8 static allocator_t
__attribute__((noinline
))
14 static allocator_t
__attribute__((noinline
))
17 /* On e.g. Solaris, alloca is a macro so we can't take its address;
18 use __builtin_alloca instead. */
19 return __builtin_alloca
;
22 static deallocator_t
__attribute__((noinline
))
28 void test_1 (void *ptr
)
30 deallocator_t dealloc_fn
= free
;
31 dealloc_fn (ptr
); /* { dg-message "first 'free' here" } */
32 dealloc_fn (ptr
); /* { dg-warning "double-'free'" } */
35 void test_2 (void *ptr
)
37 deallocator_t dealloc_fn
= get_free ();
38 dealloc_fn (ptr
); /* { dg-message "first 'free' here" } */
39 dealloc_fn (ptr
); /* { dg-warning "double-'free'" } */
42 static void __attribute__((noinline
))
43 called_by_test_3 (void *ptr
, deallocator_t dealloc_fn
)
45 dealloc_fn (ptr
); /* { dg-warning "double-'free'" } */
48 void test_3 (void *ptr
)
50 called_by_test_3 (ptr
, free
);
51 called_by_test_3 (ptr
, free
);
56 allocator_t alloc_fn
= get_malloc ();
57 int *ptr
= (int *) alloc_fn (sizeof (int)); /* { dg-message "this call could return NULL" } */
58 *ptr
= 42; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
64 allocator_t alloc_fn
= get_alloca ();
65 deallocator_t dealloc_fn
= get_free ();
66 int *ptr
= (int *) alloc_fn (sizeof (int)); /* dg-message "region created on stack here" } */
67 dealloc_fn (ptr
); /* { dg-warning "'free' of 'ptr' which points to memory on the stack" } */
70 static void __attribute__((noinline
))
71 called_by_test_6a (void *ptr
)
73 free (ptr
); /* { dg-warning "double-'free'" } */
76 static deallocator_t
__attribute__((noinline
))
77 called_by_test_6b (void)
79 return called_by_test_6a
;
82 void test_6 (void *ptr
)
84 deallocator_t dealloc_fn
= called_by_test_6b ();