Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/malloc-ipa-1.c

raw
1 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
2
3 #include <stdlib.h>
4
5 void *
6 calls_malloc (void)
7 {
8 void *result = malloc (1024);
9 return result;
10 }
11
12 int *test_1 (int i)
13 {
14 int *ptr = (int *)calls_malloc ();
15 *ptr = i; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
16 return ptr;
17 }
18
19 /* Same as test_1, to exercise the caches. */
20
21 int *test_2 (int i)
22 {
23 int *ptr = (int *)calls_malloc ();
24 *ptr = i; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
25 return ptr;
26 }