1 /* PR middle-end/94527 - Add an attribute that marks a function as freeing
3 Verify that attribute malloc with one or two arguments is accepted where
4 intended and rejected where it's invalid.
5 { dg-options "-Wall -ftrack-macro-expansion=0" } */
7 #define A(...) __attribute__ ((malloc (__VA_ARGS__)))
9 A (0) void* alloc_zero (int); // { dg-error "'malloc' attribute argument 1 does not name a function" }
11 A ("") void* alloc_string (int); // { dg-error "'malloc' attribute argument 1 does not name a function" }
14 A (var
) void* alloc_var (int); // { dg-error "'malloc' attribute argument 1 does not name a function" }
16 typedef struct Type
{ int i
; } Type
;
17 A (Type
) void* alloc_type (int); // { dg-error "expected expression|identifier" }
19 A (unknown
) void* alloc_unknown (int); // { dg-error "'unknown' undeclared" }
21 void fv_ (); // { dg-message "declared here" }
22 A (fv_
) void* alloc_fv_ (int); // { dg-error "'malloc' attribute argument 1 must take a pointer type as its first argument" }
24 void fvi (int); // { dg-message "declared here" }
25 A (fvi
) void* alloc_fvi (int); // { dg-error "'malloc' attribute argument 1 must take a pointer type as its first argument; have 'int'" }
27 void fvv (void); // { dg-message "declared here" }
28 A (fvv
) void* alloc_fvv (int); // { dg-error "'malloc' attribute argument 1 must take a pointer type as its first argument; have 'void'" }
30 void fvi_ (int, ...); // { dg-message "declared here" }
31 A (fvi_
) void* alloc_fvi_ (int); // { dg-error "'malloc' attribute argument 1 must take a pointer type as its first argument; have 'int'" }
33 void fvi_vp (Type
, void*); // { dg-message "declared here" }
34 A (fvi_vp
) void* alloc_fvi_vp (int); // { dg-error "'malloc' attribute argument 1 must take a pointer type as its first argument; have 'Type'" }
38 A (fpv
) void* alloc_fpv (int);
40 void fpv_i (void*, int);
41 A (fpv_i
) void* alloc_fpv_i (int);
43 void fpv_pv (void*, void*);
44 A (fpv_i
) void* alloc_fpv_pv (int);
49 A (fpv
) A (gpc
) A (hpi
) Type
* alloc_fpv_gpv (int);
52 /* Verify that the attribute can be applied to <stdio.h> functions. */
53 typedef struct FILE FILE;
54 typedef __SIZE_TYPE__
size_t;
58 FILE* fopen (const char*, const char*);
59 FILE* freopen (const char*, const char*, FILE*);
61 FILE* popen (const char*, const char*);
64 A (fclose
) A (freopen
, 3) A (pclose
)
66 A (fclose
) A (freopen
, 3) A (pclose
)
67 FILE* fopen (const char*, const char*);
68 A (fclose
) A (freopen
, 3) A (pclose
)
69 FILE* fmemopen(void *, size_t, const char *);
70 A (fclose
) A (freopen
, 3) A (pclose
)
71 FILE* freopen (const char*, const char*, FILE*);
72 A (fclose
) A (freopen
, 3) A (pclose
)
73 FILE* popen (const char*, const char*);
74 A (fclose
) A (freopen
, 3) A (pclose
)