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
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(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 count;
struct bar *ptr __counted_by_or_null(bork); // expected-error {{use of undeclared identifier 'bork'}}
};
struct no_found_count_not_in_substruct {
unsigned long flags;
unsigned char count; // expected-note {{'count' declared here}}
struct A {
int dummy;
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}}
} a;
};
struct not_found_count_not_in_unnamed_substruct {
unsigned char count; // expected-note {{'count' declared here}}
struct {
int dummy;
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}}
} a;
};
struct not_found_count_not_in_unnamed_substruct_2 {
struct {
unsigned char count; // expected-note {{'count' declared here}}
};
struct {
int dummy;
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}}
} a;
};
struct not_found_count_in_other_unnamed_substruct {
struct {
unsigned char count;
} a1;
struct {
int dummy;
int * ptr __counted_by_or_null(count); // expected-error {{use of undeclared identifier 'count'}}
};
};
struct not_found_count_in_other_substruct {
struct _a1 {
unsigned char count;
} a1;
struct {
int dummy;
int * ptr __counted_by_or_null(count); // expected-error {{use of undeclared identifier 'count'}}
};
};
struct not_found_count_in_other_substruct_2 {
struct _a2 {
unsigned char count;
} a2;
int * ptr __counted_by_or_null(count); // expected-error {{use of undeclared identifier 'count'}}
};
struct not_found_suggest {
int bork;
struct bar **ptr __counted_by_or_null(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 __counted_by_or_null(global); // expected-error {{field 'global' in 'counted_by_or_null' not inside structure}}
};
struct self_referrential {
int bork;
struct bar *self[] __counted_by_or_null(self); // expected-error {{use of undeclared identifier 'self'}}
};
struct non_int_count {
double dbl_count;
struct bar ** ptr __counted_by_or_null(dbl_count); // expected-error {{'counted_by_or_null' requires a non-boolean integer type argument}}
};
struct array_of_ints_count {
int integers[2];
struct bar ** ptr __counted_by_or_null(integers); // expected-error {{'counted_by_or_null' requires a non-boolean integer type argument}}
};
struct not_a_c99_fam {
int count;
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'?}}
};
struct annotated_with_anon_struct {
unsigned long flags;
struct {
unsigned char count;
int * ptr __counted_by_or_null(crount); // expected-error {{use of undeclared identifier 'crount'}}
};
};
//==============================================================================
// __counted_by_or_null on a struct ptr with element type that has unknown count
//==============================================================================
struct count_unknown;
struct on_member_ptr_incomplete_ty_ty_pos {
int count;
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}}
};
struct on_member_ptr_incomplete_const_ty_ty_pos {
int count;
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}}
};
struct on_member_ptr_void_ty_ty_pos {
int count;
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}}
};
typedef void(fn_ty)(int);
struct on_member_ptr_fn_ptr_ty {
int count;
fn_ty* * ptr __counted_by_or_null(count);
};
struct on_member_ptr_fn_ty {
int count;
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}}
};
|