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. */
4 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-fine-grained" } */
5 /* { dg-require-effective-target alloca } */
8 #include "../../gcc.dg/analyzer/test-alloca.h"
10 void test_constant_99 (void)
12 int32_t *ptr
= (int32_t *) alloca (99); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
15 /* { dg-begin-multiline-output "" }
16 int32_t *ptr = (int32_t *) alloca (99);
18 'test_constant_99': events 1-2
19 int32_t *ptr = (int32_t *) alloca (99);
22 (1) allocated 99 bytes here
23 (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
24 { dg-end-multiline-output "" { target c } } */
25 /* { dg-begin-multiline-output "" }
26 int32_t *ptr = (int32_t *) alloca (99);
28 'void test_constant_99()': events 1-2
29 int32_t *ptr = (int32_t *) alloca (99);
32 (1) allocated 99 bytes here
33 (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
34 { dg-end-multiline-output "" { target c++ } } */
36 void test_symbolic (int n
)
38 int32_t *ptr
= (int32_t *) alloca (n
* 2); /* { dg-warning "allocated buffer size is not a multiple of the pointee's size" } */
41 /* { dg-begin-multiline-output "" }
42 int32_t *ptr = (int32_t *) alloca (n * 2);
44 'test_symbolic': events 1-2
45 int32_t *ptr = (int32_t *) alloca (n * 2);
48 (1) allocated 'n * 2' bytes here
49 (2) assigned to 'int32_t *' {aka '{re:long :re?}int *'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
50 { dg-end-multiline-output "" { target c } } */
51 /* { dg-begin-multiline-output "" }
52 int32_t *ptr = (int32_t *) alloca (n * 2);
54 'void test_symbolic(int)': events 1-2
55 int32_t *ptr = (int32_t *) alloca (n * 2);
58 (1) allocated '(n * 2)' bytes here
59 (2) assigned to 'int32_t*' {aka '{re:long :re?}int*'} here; 'sizeof (int32_t {aka {re:long :re?}int})' is '4'
60 { dg-end-multiline-output "" { target c++ } } */