[clang] [Sema] Call ActOnFields before late parsing in ParseStructUnionBody (PR #187166)
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 05:17:56 PDT 2026
zmodem wrote:
> > Move the call to ActOnFields() before ParseLexedCAttributeList() in ParseStructUnionBody for reordering so that the struct type is complete when late-parsed attributes like counted_by get evaluated.
>
> Someone who knows the parser better can correct me here, but intuitively the new ordering seems odd to me. Shouldn't `ActOnFields()` be able to assume that the fields have been fully parsed, including their attributes?
Looking at this some more, I suppose it depends on what the contract is for `ActOnFields()`.
Since we can decide that ourselves, it seems fair enough to say that "late parsed" for field attributes means they're parsed after `ActOnFields()`, and that the consumer can inspect them in `ActOnTagFinishDefinition()`.
> That said, for a change which is explicitly made to support `sizeof` and `offsetof`, shouldn't there be test cases exercising those?
+1
@Pengxiang-Huang maybe just add something like this:
```
#define offsetof(t, d) __builtin_offsetof(t, d)
struct S {
int *p __counted_by(sizeof(struct S));
int *q __counted_by(offsetof(struct S, q));
};
```
https://github.com/llvm/llvm-project/pull/187166
More information about the cfe-commits
mailing list