[clang] [Clang] Add __builtin_counted_by_ref builtin (PR #114495)

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 17:56:14 PST 2024


================
@@ -16,6 +16,8 @@ void test1(struct fam_struct *ptr, int size, int idx) {
 
   *__builtin_counted_by_ref(ptr->array) = size;             // ok
   *__builtin_counted_by_ref(&ptr->array[idx]) = size;       // ok
+  *__builtin_counted_by_ref(&ptr->array) = size;            // ok
----------------
bwendling wrote:

Note that, because GCC only checks if the argument is an array, it allows for things like:

```c
int global_array[];

void foo(int val) {
  *__builtin_counted_by_ref(global_array) = val;
}
```

which isn't great.

https://github.com/llvm/llvm-project/pull/114495


More information about the cfe-commits mailing list