Debian Codegraph @

clang/test/Sema/attr-malloc_span.c

raw
1 // RUN: %clang_cc1 -verify -fsyntax-only %s
2
3 typedef __SIZE_TYPE__ size_t;
4
5 typedef struct {
6 void *ptr;
7 size_t n;
8 } span;
9 span returns_span (void) __attribute((malloc_span)); // no-warning
10
11 typedef struct {
12 size_t n;
13 void *ptr;
14 } span2;
15 span2 returns_span2 (void) __attribute((malloc_span)); // no-warning
16
17 typedef struct {
18 void *ptr;
19 void *ptr2;
20 } span3;
21 span3 returns_span3 (void) __attribute((malloc_span)); // no-warning
22
23 typedef struct {
24 void *ptr;
25 int n;
26 } span4;
27 span4 returns_span4 (void) __attribute((malloc_span)); // no-warning
28
29 typedef struct incomplete_span incomplete_span;
30 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
31 // expected-note@+1 {{returned type is incomplete}}
32 incomplete_span returns_incomplete_span (void) __attribute((malloc_span));
33
34 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
35 // expected-note@+1 {{returned type is not a struct type}}
36 int *returns_int_ptr (void) __attribute((malloc_span));
37
38 typedef struct {
39 void *ptr;
40 size_t n;
41 size_t n2;
42 } too_long_span;
43 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
44 // expected-note@+1 {{returned struct has 3 fields, expected 2}}
45 too_long_span returns_too_long_span (void) __attribute((malloc_span));
46
47 // Function pointers are not allowed.
48 typedef struct {
49 int (*func_ptr)(void);
50 size_t n;
51 } func_span;
52 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
53 // expected-note@+1 {{returned struct fields are not a supported combination}}
54 func_span returns_func_span (void) __attribute((malloc_span));
55
56 // Integer should not be an enum.
57 enum some_enum { some_value, other_value };
58 typedef struct {
59 void *ptr;
60 enum some_enum field;
61 } enum_span;
62 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
63 // expected-note@+1 {{2nd field is expected to be an integer}}
64 enum_span returns_enum_span (void) __attribute((malloc_span));
65
66 // Bit integers are also not supported.
67 typedef struct {
68 void *ptr;
69 _BitInt(16) n;
70 } bit_span;
71 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
72 // expected-note@+1 {{2nd field is expected to be an integer}}
73 bit_span returns_bit_span (void) __attribute((malloc_span));
74
75 // Integer must be at least as big as int.
76 typedef struct {
77 void *ptr;
78 short n;
79 } short_span;
80 // expected-warning@+2 {{attribute only applies to functions that return span-like structures}}
81 // expected-note@+1 {{2nd field of span-like type is not a wide enough integer (minimum width: 32)}}
82 short_span returns_short_span (void) __attribute((malloc_span));