1 // RUN: %clang_cc1 %s -ast-dump | FileCheck %s
2 // RUN: %clang_cc1 -fexperimental-late-parse-attributes %s -ast-dump | FileCheck %s
4 #define __counted_by(f) __attribute__((counted_by(f)))
11 //==============================================================================
12 // __counted_by on struct member pointer in decl attribute position
13 //==============================================================================
15 // CHECK-LABEL: RecordDecl {{.+}} struct on_member_pointer_complete_ty definition
16 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
17 // CHECK-NEXT: `-FieldDecl {{.+}} buf 'struct size_known * __counted_by(count)':'struct size_known *'
18 struct on_member_pointer_complete_ty
{
20 struct size_known
* buf
__counted_by(count
);
23 // CHECK-LABEL: RecordDecl {{.+}} struct on_pointer_anon_buf definition
24 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
25 // CHECK-NEXT: |-RecordDecl {{.+}} struct definition
26 // CHECK-NEXT: | `-FieldDecl {{.+}} buf 'struct size_known * __counted_by(count)':'struct size_known *'
27 // CHECK-NEXT: |-FieldDecl {{.+}} implicit 'struct on_pointer_anon_buf::(anonymous at [[ANON_STRUCT_PATH:.+]])'
28 // CHECK-NEXT: `-IndirectFieldDecl {{.+}} implicit buf 'struct size_known * __counted_by(count)':'struct size_known *'
29 // CHECK-NEXT: |-Field {{.+}} '' 'struct on_pointer_anon_buf::(anonymous at [[ANON_STRUCT_PATH]])'
30 // CHECK-NEXT: `-Field {{.+}} 'buf' 'struct size_known * __counted_by(count)':'struct size_known *'
31 struct on_pointer_anon_buf
{
34 struct size_known
*buf
__counted_by(count
);
38 struct on_pointer_anon_count
{
42 struct size_known
*buf
__counted_by(count
);
45 //==============================================================================
46 // __counted_by on struct member pointer in type attribute position
47 //==============================================================================
48 // TODO: Correctly parse counted_by as a type attribute. Currently it is parsed
49 // as a declaration attribute
51 // CHECK-LABEL: RecordDecl {{.+}} struct on_member_pointer_complete_ty_ty_pos definition
52 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
53 // CHECK-NEXT: `-FieldDecl {{.+}} buf 'struct size_known * __counted_by(count)':'struct size_known *'
54 struct on_member_pointer_complete_ty_ty_pos
{
56 struct size_known
*__counted_by(count
) buf
;
59 // TODO: This should be forbidden but isn't due to counted_by being treated as a
60 // declaration attribute. The attribute ends up on the outer most pointer
61 // (allowed by sema) even though syntactically its supposed to be on the inner
62 // pointer (would not allowed by sema due to pointee being a function type).
63 // CHECK-LABEL: RecordDecl {{.+}} struct on_member_pointer_fn_ptr_ty_ty_pos_inner definition
64 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
65 // CHECK-NEXT: `-FieldDecl {{.+}} fn_ptr 'void (** __counted_by(count))(void)':'void (**)(void)'
66 struct on_member_pointer_fn_ptr_ty_ty_pos_inner
{
68 void (* __counted_by(count
) * fn_ptr
)(void);
71 // FIXME: The generated AST here is wrong. The attribute should be on the inner
73 // CHECK-LABEL: RecordDecl {{.+}} struct on_nested_pointer_inner definition
74 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
75 // CHECK-NEXT: `-FieldDecl {{.+}} buf 'struct size_known ** __counted_by(count)':'struct size_known **'
76 struct on_nested_pointer_inner
{
78 // TODO: This should be disallowed because in the `-fbounds-safety` model
79 // `__counted_by` can only be nested when used in function parameters.
80 struct size_known
*__counted_by(count
) *buf
;
83 // CHECK-LABEL: RecordDecl {{.+}} struct on_nested_pointer_outer definition
84 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
85 // CHECK-NEXT: `-FieldDecl {{.+}} buf 'struct size_known ** __counted_by(count)':'struct size_known **'
86 struct on_nested_pointer_outer
{
88 struct size_known
**__counted_by(count
) buf
;
91 // CHECK-LABEL: RecordDecl {{.+}} struct on_pointer_anon_buf_ty_pos definition
92 // CHECK-NEXT: |-FieldDecl {{.+}} referenced count 'int'
93 // CHECK-NEXT: |-RecordDecl {{.+}} struct definition
94 // CHECK-NEXT: | `-FieldDecl {{.+}} buf 'struct size_known * __counted_by(count)':'struct size_known *'
95 // CHECK-NEXT: |-FieldDecl {{.+}} implicit 'struct on_pointer_anon_buf_ty_pos::(anonymous at [[ANON_STRUCT_PATH2:.+]])'
96 // CHECK-NEXT: `-IndirectFieldDecl {{.+}} implicit buf 'struct size_known * __counted_by(count)':'struct size_known *'
97 // CHECK-NEXT: |-Field {{.+}} '' 'struct on_pointer_anon_buf_ty_pos::(anonymous at [[ANON_STRUCT_PATH2]])'
98 // CHECK-NEXT: `-Field {{.+}} 'buf' 'struct size_known * __counted_by(count)':'struct size_known *'
99 struct on_pointer_anon_buf_ty_pos
{
102 struct size_known
* __counted_by(count
) buf
;
106 // CHECK-LABEL: RecordDecl {{.+}} struct on_pointer_anon_count_ty_pos definition
107 // CHECK-NEXT: |-RecordDecl {{.+}} struct definition
108 // CHECK-NEXT: | `-FieldDecl {{.+}} count 'int'
109 // CHECK-NEXT: |-FieldDecl {{.+}} implicit 'struct on_pointer_anon_count_ty_pos::(anonymous at [[ANON_STRUCT_PATH3:.+]])'
110 // CHECK-NEXT: |-IndirectFieldDecl {{.+}} implicit referenced count 'int'
111 // CHECK-NEXT: | |-Field {{.+}} '' 'struct on_pointer_anon_count_ty_pos::(anonymous at [[ANON_STRUCT_PATH3]])'
112 // CHECK-NEXT: | `-Field {{.+}} 'count' 'int'
113 struct on_pointer_anon_count_ty_pos
{
117 struct size_known
*__counted_by(count
) buf
;