llvm-project
llvm-project copied to clipboard
counted_by() fails on some types of count variables
The counted_by() attribute takes an integer/size_t/whatever as its argument. If this is a standalone integer 'count' it's fine but if it's an integer that's part of something else like a struct, 'foo.count', clang fails with:
error: 'counted_by' argument must be a simple declaration reference
The following code, a cut-down test case from a larger codebase, demonstrates this:
struct countinfo {
int totalcount, indexcount;
};
struct thing1 {
int count;
char buffer[] __attribute__((counted_by(count)));
};
struct thing2 {
struct countinfo count;
char buffer[] __attribute__((counted_by(count.totalcount)));
};
In both cases the count values are integers, but the second one is rejected.
@llvm/issue-subscribers-clang-frontend
Author: fencepost-error
The counted_by() attribute takes an integer/size_t/whatever as its argument. If this is a standalone integer 'count' it's fine but if it's an integer that's part of something else like a struct, 'foo.count', clang fails with:
error: 'counted_by' argument must be a simple declaration reference
The following code, a cut-down test case from a larger codebase, demonstrates this:
struct countinfo {
int totalcount, indexcount;
};
struct thing1 {
int count;
char buffer[] __attribute__((counted_by(count)));
};
struct thing2 {
struct countinfo count;
char buffer[] __attribute__((counted_by(count.totalcount)));
};
In both cases the count values are integers, but the second one is rejected.