llvm-project
llvm-project copied to clipboard
Support late parsing for `__counted_by` attributes in type position
Problem:
__counted_by and related attributes must be treated as type attributes to enable future support for valid use cases such as:
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:
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