Debian Codegraph @

clang/test/Sema/attr-counted-by-bounds-safety-vlas.c

raw
1 // RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s
2 //
3 // This is a portion of the `attr-counted-by-vla.c` test but is checked
4 // under the semantics of `-fexperimental-bounds-safety` which has different
5 // behavior.
6
7 #define __counted_by(f) __attribute__((counted_by(f)))
8
9 struct has_unannotated_VLA {
10 int count;
11 char buffer[];
12 };
13
14 struct has_annotated_VLA {
15 int count;
16 char buffer[] __counted_by(count);
17 };
18
19 struct buffer_of_structs_with_unnannotated_vla {
20 int count;
21 // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_unannotated_VLA' is a struct type with a flexible array member}}
22 struct has_unannotated_VLA Arr[] __counted_by(count);
23 };
24
25
26 struct buffer_of_structs_with_annotated_vla {
27 int count;
28 // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'struct has_annotated_VLA' is a struct type with a flexible array member}}
29 struct has_annotated_VLA Arr[] __counted_by(count);
30 };
31
32 struct buffer_of_const_structs_with_annotated_vla {
33 int count;
34 // Make sure the `const` qualifier is printed when printing the element type.
35 // expected-error@+1{{'counted_by' cannot be applied to an array with element of unknown size because 'const struct has_annotated_VLA' is a struct type with a flexible array member}}
36 const struct has_annotated_VLA Arr[] __counted_by(count);
37 };