testsuite: Skip analyzer tests on AIX.
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / capacity-1.c
blobcfee1159826a5fba6f1034d79457fa2a73f6d761
1 /* { dg-require-effective-target alloca } */
2 /* { dg-skip-if "" { powerpc*-*-aix* } } */
4 #include <stdlib.h>
5 #include "../../gcc.dg/analyzer/analyzer-decls.h"
7 typedef unsigned __INT32_TYPE__ u32;
9 void
10 test_1 (void)
12 char buf[16];
13 __analyzer_dump_capacity (buf); /* { dg-warning "capacity: '\\(sizetype\\)16'" } */
16 void
17 test_2 (void)
19 char ch;
20 __analyzer_dump_capacity (&ch); /* { dg-warning "capacity: '\\(sizetype\\)1'" } */
23 struct s3 { char buf[100]; };
25 void
26 test_3 (void)
28 struct s3 s;
29 __analyzer_dump_capacity (&s); /* { dg-warning "capacity: '\\(sizetype\\)100'" } */
32 /* Capacity refers to the base region, not any offset within it. */
34 void
35 test_4 (void)
37 char buf[1024];
38 __analyzer_dump_capacity (buf + 100); /* { dg-warning "capacity: '\\(sizetype\\)1024'" } */
41 void
42 test_5 (void *p)
44 __analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */
47 void
48 test_malloc (void)
50 void *p = malloc (1024);
52 __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(size_t\\)1024'" } */
53 free (p);
56 void
57 test_alloca (size_t sz)
59 void *p = __builtin_alloca (sz);
60 __analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */
63 void
64 test_vla (size_t sz)
66 char buf[sz];
67 __analyzer_dump_capacity (buf); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */
70 static void * __attribute__((noinline))
71 called_by_test_interproc_malloc (size_t a)
73 return malloc (a);
76 void *
77 test_interproc_malloc (size_t sz)
79 void *p = called_by_test_interproc_malloc (sz);
80 __analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */
81 return p;
84 struct s
86 u32 f1;
87 char arr[];
90 static struct s * __attribute__((noinline))
91 alloc_s (size_t num)
93 struct s *p = (struct s *) malloc (sizeof(struct s) + num);
94 return p;
97 struct s *
98 test_trailing_array (void)
100 struct s *p = alloc_s (5);
101 __analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)9'" } */
102 return p;
105 void
106 test_unknown_arr (int p[])
108 __analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */