Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/allocation-size-multiline-3.c

raw
1 /* Verify that we warn for incorrect uses of "alloca" (which may be in a
2 macro in a system header), and that the output looks correct. */
3
4 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
5
6 #include <stdint.h>
7 #include "../../gcc.dg/analyzer/test-alloca.h"
8
9 void test_constant_99 (void)
10 {
11 int32_t *ptr = (int32_t *) alloca (99); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
12 }
13
14 /* { dg-begin-multiline-output "" }
15 int32_t *ptr = (int32_t *) alloca (99);
16 ^~~~~~
17 'test_constant_99': events 1-2
18 int32_t *ptr = (int32_t *) alloca (99);
19 ^~~~~~
20 |
21 (1) allocated 99 bytes here
22 (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
23 { dg-end-multiline-output "" { target c } } */
24 /* { dg-begin-multiline-output "" }
25 int32_t *ptr = (int32_t *) alloca (99);
26 ^~~~~~
27 'void test_constant_99()': events 1-2
28 int32_t *ptr = (int32_t *) alloca (99);
29 ^~~~~~
30 |
31 (1) allocated 99 bytes here
32 (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
33 { dg-end-multiline-output "" { target c++ } } */
34
35 void test_symbolic (int n)
36 {
37 int32_t *ptr = (int32_t *) alloca (n * 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
38 }
39
40 /* { dg-begin-multiline-output "" }
41 int32_t *ptr = (int32_t *) alloca (n * 2);
42 ^~~~~~
43 'test_symbolic': events 1-2
44 int32_t *ptr = (int32_t *) alloca (n * 2);
45 ^~~~~~
46 |
47 (1) allocated 'n * 2' bytes here
48 (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
49 { dg-end-multiline-output "" { target c } } */
50 /* { dg-begin-multiline-output "" }
51 int32_t *ptr = (int32_t *) alloca (n * 2);
52 ^~~~~~
53 'void test_symbolic(int)': events 1-2
54 int32_t *ptr = (int32_t *) alloca (n * 2);
55 ^~~~~~
56 |
57 (1) allocated '(n * 2)' bytes here
58 (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
59 { dg-end-multiline-output "" { target c++ } } */