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 // RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -fexperimental-late-parse-attributes -verify %s
3 //
4 // This is a portion of the `attr-counted-by-vla.c` test but is checked
5 // under the semantics of `-fexperimental-bounds-safety` which has different
6 // behavior.
7
8 #define __counted_by(f) __attribute__((counted_by(f)))
9
10 struct has_unannotated_VLA {
11 int count;
12 char buffer[];
13 };
14
15 struct has_annotated_VLA {
16 int count;
17 char buffer[] __counted_by(count);
18 };
19
20 struct buffer_of_structs_with_unnannotated_vla {
21 int count;
22 // 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}}
23 struct has_unannotated_VLA Arr[] __counted_by(count);
24 };
25
26
27 struct buffer_of_structs_with_annotated_vla {
28 int count;
29 // 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}}
30 struct has_annotated_VLA Arr[] __counted_by(count);
31 };
32
33 struct buffer_of_const_structs_with_annotated_vla {
34 int count;
35 // Make sure the `const` qualifier is printed when printing the element type.
36 // 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}}
37 const struct has_annotated_VLA Arr[] __counted_by(count);
38 };