Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/allocation-size-multiline-4.c

raw
1 /* Verify that we report events that occur at returns from functions
2 with valid-looking interprocedural paths.
3
4 C only: there are only minor C/C++ differences in e.g. how the
5 function names are printed. Trying to handle both would overcomplicate
6 the test. */
7
8 /* { dg-additional-options "-fdiagnostics-show-line-numbers" } */
9 /* { dg-enable-nn-line-numbers "" } */
10 /* { dg-additional-options "-fdiagnostics-path-format=inline-events" } */
11 /* { dg-additional-options "-fdiagnostics-show-caret" } */
12 /* { dg-additional-options "-fdiagnostics-show-path-depths" } */
13
14 #include <stdlib.h>
15 #include <stdint.h>
16
17 void *create_buffer (int32_t n)
18 {
19 return malloc(n);
20 }
21
22 void test_9 (void)
23 {
24 int32_t *buf = (int32_t *) create_buffer(42); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
25 free (buf);
26 }
27
28 /* { dg-begin-multiline-output "" }
29 NN | int32_t *buf = (int32_t *) create_buffer(42);
30 | ^~~~~~~~~~~~~~~~~
31 'test_9': events 1-2 (depth 1)
32 |
33 | NN | void test_9 (void)
34 | | ^~~~~~
35 | | |
36 | | (1) entry to 'test_9'
37 | NN | {
38 | NN | int32_t *buf = (int32_t *) create_buffer(42);
39 | | ~~~~~~~~~~~~~~~~~
40 | | |
41 | | (2) calling 'create_buffer' from 'test_9'
42 |
43 +--> 'create_buffer': events 3-4 (depth 2)
44 |
45 | NN | void *create_buffer (int32_t n)
46 | | ^~~~~~~~~~~~~
47 | | |
48 | | (3) entry to 'create_buffer'
49 | NN | {
50 | NN | return malloc(n);
51 | | ~~~~~~~~~
52 | | |
53 | | (4) allocated 42 bytes here
54 |
55 <------+
56 |
57 'test_9': event 5 (depth 1)
58 |
59 | NN | int32_t *buf = (int32_t *) create_buffer(42);
60 | | ^~~~~~~~~~~~~~~~~
61 | | |
62 | | (5) assigned to 'int32_t *'
63 |
64 { dg-end-multiline-output "" } */