blob: f2e74f7fdf4b5105230acad57ac01e2e09f1cfac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// RUN: %clang_cc1 -fsyntax-only -verify=expected,immediate %s
// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify=expected,late %s
#define __sized_by(f) __attribute__((sized_by(f)))
// This has been adapted from clang/test/Sema/attr-counted-by-vla.c, but with VLAs replaced with pointers
struct bar;
struct not_found {
int size;
struct bar *ptr __sized_by(bork); // expected-error {{use of undeclared identifier 'bork'}}
};
struct no_found_size_not_in_substruct {
unsigned long flags;
unsigned char size; // expected-note {{'size' declared here}}
struct A {
int dummy;
int * ptr __sized_by(size); // expected-error {{'sized_by' field 'size' isn't within the same struct as the annotated pointer}}
} a;
};
struct not_found_size_not_in_unnamed_substruct {
unsigned char size; // expected-note {{'size' declared here}}
struct {
int dummy;
int * ptr __sized_by(size); // expected-error {{'sized_by' field 'size' isn't within the same struct as the annotated pointer}}
} a;
};
struct not_found_size_not_in_unnamed_substruct_2 {
struct {
unsigned char size; // expected-note {{'size' declared here}}
};
struct {
int dummy;
int * ptr __sized_by(size); // expected-error {{'sized_by' field 'size' isn't within the same struct as the annotated pointer}}
} a;
};
struct not_found_size_in_other_unnamed_substruct {
struct {
unsigned char size;
} a1;
struct {
int dummy;
int * ptr __sized_by(size); // expected-error {{use of undeclared identifier 'size'}}
};
};
struct not_found_size_in_other_substruct {
struct _a1 {
unsigned char size;
} a1;
struct {
int dummy;
int * ptr __sized_by(size); // expected-error {{use of undeclared identifier 'size'}}
};
};
struct not_found_size_in_other_substruct_2 {
struct _a2 {
unsigned char size;
} a2;
int * ptr __sized_by(size); // expected-error {{use of undeclared identifier 'size'}}
};
struct not_found_suggest {
int bork;
struct bar **ptr __sized_by(blork); // expected-error {{use of undeclared identifier 'blork'}}
};
int global; // expected-note {{'global' declared here}}
struct found_outside_of_struct {
int bork;
struct bar ** ptr __sized_by(global); // expected-error {{field 'global' in 'sized_by' not inside structure}}
};
struct self_referrential {
int bork;
// immediate-error@+2{{use of undeclared identifier 'self'}}
// late-error@+1{{'sized_by' only applies to pointers; did you mean to use 'counted_by'?}}
struct bar *self[] __sized_by(self);
};
struct non_int_size {
double dbl_size;
struct bar ** ptr __sized_by(dbl_size); // expected-error {{'sized_by' requires a non-boolean integer type argument}}
};
struct array_of_ints_size {
int integers[2];
struct bar ** ptr __sized_by(integers); // expected-error {{'sized_by' requires a non-boolean integer type argument}}
};
struct not_a_c99_fam {
int size;
struct bar *non_c99_fam[0] __sized_by(size); // expected-error {{'sized_by' only applies to pointers; did you mean to use 'counted_by'?}}
};
struct annotated_with_anon_struct {
unsigned long flags;
struct {
unsigned char size;
int * ptr __sized_by(crount); // expected-error {{use of undeclared identifier 'crount'}}
};
};
//==============================================================================
// __sized_by on a struct ptr with element type that has unknown size
//==============================================================================
struct size_unknown;
struct on_member_ptr_incomplete_ty_ty_pos {
int size;
struct size_unknown * ptr __sized_by(size);
};
struct on_member_ptr_incomplete_const_ty_ty_pos {
int size;
const struct size_unknown * ptr __sized_by(size);
};
struct on_member_ptr_void_ty_ty_pos {
int size;
void * ptr __sized_by(size);
};
typedef void(fn_ty)(int);
struct on_member_ptr_fn_ptr_ty {
int size;
fn_ty* * ptr __sized_by(size);
};
struct on_member_ptr_fn_ty {
int size;
// expected-error@+1{{'sized_by' cannot be applied to a pointer with pointee of unknown size because 'fn_ty' (aka 'void (int)') is a function type}}
fn_ty * ptr __sized_by(size);
};
|