1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,immediate %s
2 // RUN: %clang_cc1 -fsyntax-only -fexperimental-late-parse-attributes -verify=expected,late %s
4 #define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
6 // This has been adapted from clang/test/Sema/attr-counted-by-vla.c, but with VLAs replaced with pointers
12 struct bar
*ptr
__counted_by_or_null(bork
); // expected-error {{use of undeclared identifier 'bork'}}
15 struct no_found_count_not_in_substruct
{
17 unsigned char count
; // expected-note {{'count' declared here}}
20 int * ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' field 'count' isn't within the same struct as the annotated pointer}}
24 struct not_found_count_not_in_unnamed_substruct
{
25 unsigned char count
; // expected-note {{'count' declared here}}
28 int * ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' field 'count' isn't within the same struct as the annotated pointer}}
32 struct not_found_count_not_in_unnamed_substruct_2
{
34 unsigned char count
; // expected-note {{'count' declared here}}
38 int * ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' field 'count' isn't within the same struct as the annotated pointer}}
42 struct not_found_count_in_other_unnamed_substruct
{
49 int * ptr
__counted_by_or_null(count
); // expected-error {{use of undeclared identifier 'count'}}
53 struct not_found_count_in_other_substruct
{
60 int * ptr
__counted_by_or_null(count
); // expected-error {{use of undeclared identifier 'count'}}
64 struct not_found_count_in_other_substruct_2
{
69 int * ptr
__counted_by_or_null(count
); // expected-error {{use of undeclared identifier 'count'}}
72 struct not_found_suggest
{
74 struct bar
**ptr
__counted_by_or_null(blork
); // expected-error {{use of undeclared identifier 'blork'}}
77 int global
; // expected-note {{'global' declared here}}
79 struct found_outside_of_struct
{
81 struct bar
** ptr
__counted_by_or_null(global
); // expected-error {{field 'global' in 'counted_by_or_null' not inside structure}}
84 struct self_referrential
{
86 // immediate-error@+2{{use of undeclared identifier 'self'}}
87 // late-error@+1{{'counted_by_or_null' only applies to pointers; did you mean to use 'counted_by'?}}
88 struct bar
*self
[] __counted_by_or_null(self
);
91 struct non_int_count
{
93 struct bar
** ptr
__counted_by_or_null(dbl_count
); // expected-error {{'counted_by_or_null' requires a non-boolean integer type argument}}
96 struct array_of_ints_count
{
98 struct bar
** ptr
__counted_by_or_null(integers
); // expected-error {{'counted_by_or_null' requires a non-boolean integer type argument}}
101 struct not_a_c99_fam
{
103 struct bar
*non_c99_fam
[0] __counted_by_or_null(count
); // expected-error {{'counted_by_or_null' only applies to pointers; did you mean to use 'counted_by'?}}
106 struct annotated_with_anon_struct
{
110 int * ptr
__counted_by_or_null(crount
); // expected-error {{use of undeclared identifier 'crount'}}
114 //==============================================================================
115 // __counted_by_or_null on a struct ptr with element type that has unknown count
116 //==============================================================================
118 struct count_unknown
;
119 struct on_member_ptr_incomplete_ty_ty_pos
{
121 struct count_unknown
* ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'struct count_unknown' is an incomplete type}}
124 struct on_member_ptr_incomplete_const_ty_ty_pos
{
126 const struct count_unknown
* ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'const struct count_unknown' is an incomplete type}}
129 struct on_member_ptr_void_ty_ty_pos
{
131 void * ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'void' is an incomplete type}}
134 typedef void(fn_ty
)(int);
136 struct on_member_ptr_fn_ptr_ty
{
138 fn_ty
* * ptr
__counted_by_or_null(count
);
141 struct on_member_ptr_fn_ty
{
143 fn_ty
* ptr
__counted_by_or_null(count
); // expected-error {{'counted_by_or_null' cannot be applied to a pointer with pointee of unknown size because 'fn_ty' (aka 'void (int)') is a function type}}