[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)
Dan Liew via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 8 09:15:33 PDT 2024
================
@@ -0,0 +1,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}}
----------------
delcypher wrote:
Nit: This wording is a little odd. I would expect something like.
```
'counted_by_or_null' references field 'count' which isn't within the same struct as the annotated pointer
```
https://github.com/llvm/llvm-project/pull/93231
More information about the cfe-commits
mailing list