Issue 166411
Summary Support late parsing for `__counted_by` attributes in type position
Labels clang:bounds-safety
Assignees rapidsna
Reporter rapidsna
    ### Problem:

`__counted_by` and related attributes must be treated as type attributes to enable future support for valid use cases such as:

```C
void foo(int *__counted_by(*out_count) *out_buffer, size_t *out_count);

typedef int *__counted_by(10) ARRY_OF_INT_10_T;
```

*Note: These use cases are not yet supported, as __counted_by currently only works within struct definitions.*

However, even within structs, we should correctly reject attributes on nested type positions where the count field is not yet in scope:

```C
struct nested_counted_by {
  int count;
  int *__counted_by(count) *buf; // error
};

struct late_parsed_nested_counted_by {
  int *__counted_by(count) *buf; // error
  int count;
};
```

### Current behavior:

- Late parsing only recognizes attributes in declaration position, not type position
- __counted_by attributes on nested type positions are incorrectly attached to the outermost pointer type because they are being treated as GNU-style declaration attributes rather than type attributes

### Expected behavior:

- Extend late parsing to support attributes in type position
- Reject invalid nested pointer cases with clear diagnostics
- Lay groundwork for future support of __counted_by in function parameters and typedefs
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to