1 /* PR middle-end/81871 - bogus attribute alloc_align accepted
2    Test exercising the problem with attribute alloc_size.
3    { dg-do compile }
4    { dg-options "-Wall" } */
5 
6 #define ASIZE(...)   __attribute__ ((alloc_size (__VA_ARGS__)))
7 #define SIZE_MAX  __SIZE_MAX__
8 
9 ASIZE (-1) void fvv_m1 (void);    /* { dg-warning ".alloc_size. attribute ignored on a function returning .void." } */
10 
11 ASIZE (1) int fiv_1 (void);       /* { dg-warning ".alloc_size. attribute ignored on a function returning .int." } */
12 
13 ASIZE (1, 2) int fiv_1_2 (void);  /* { dg-warning ".alloc_size. attribute ignored on a function returning .int." } */
14 
15 ASIZE (0) void* fpvv_0 (void);    /* { dg-warning ".alloc_size. attribute argument value .0. does not refer to a function parameter" } */
16 
17 ASIZE (1, 0) void*
18 fpvv_1_0 (int);                   /* { dg-warning ".alloc_size. attribute argument 2 value .0. does not refer to a function parameter" } */
19 
20 ASIZE (1) void* fpvv_1 (void);    /* { dg-warning ".alloc_size. attribute argument value .1. exceeds the number of function parameters 0" } */
21 
22 ASIZE (1, 9) void*
23 fpvv_1_9 (int);                   /* { dg-warning ".alloc_size. attribute argument 2 value .9. exceeds the number of function parameters 1" } */
24 
25 ASIZE (2) void* fii_2 (int);      /* { dg-warning ".alloc_size. attribute argument value .2. exceeds the number of function parameters 1" } */
26 
27 ASIZE (1) void fvi_1 (int);       /* { dg-warning ".alloc_size. attribute ignored on a function returning .void." } */
28 
29 /* Using alloc_size with a function returning a pointer to a function
30    should perhaps trigger a warning.  */
31 typedef void (F)(void);
32 ASIZE (1) F* fpF_i_1 (int);
33 
34 ASIZE (SIZE_MAX) void*
35 fpvi_szmax (int);                 /* { dg-warning ".alloc_size. attribute argument value .\[0-9\]+. exceeds the number of function parameters 1" } */
36 
37 ASIZE ("12") void*
38 fpvi_str_1 (int);                 /* { dg-warning ".alloc_size. attribute argument has type .char\\\[3]." } */
39 
40 ASIZE (1, "123") void*
41 fpvi_str_2 (int, int);            /* { dg-warning ".alloc_size. attribute argument 2 has type .char\\\[4]." } */
42 
43 ASIZE ((void*)0) void*
44 fpvi_pv0 (int);                   /* { dg-warning ".alloc_size. attribute argument has type .void \\\*." } */
45 
46 ASIZE ((double*)sizeof (double)) void*
47 fpvi_pd1 (int);                   /* { dg-warning ".alloc_size. attribute argument has type .double \\\*." } */
48 
49 ASIZE (1) void*
50 fpvi_pv_1 (void*);                /* { dg-warning ".alloc_size. attribute argument value .1. refers to parameter type .void \\\*." } */
51 
52 struct S { int i; };
53 ASIZE (2) void*
54 fpvi_S_2 (int, struct S);         /* { dg-warning ".alloc_size. attribute argument value .2. refers to parameter type .struct S." } */
55 
56 ASIZE ((struct S){ 1 }) void*
57 fpvi_S (int);                     /* { dg-warning ".alloc_size. attribute argument has type .struct S." } */
58 
59 ASIZE (1, (struct S){ 1 }) void*
60 fpvi_1_S (int);                   /* { dg-warning ".alloc_size. attribute argument 2 has type .struct S." } */
61