llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

counted_by() fails on some types of count variables

Open fencepost-error opened this issue 1 month ago • 1 comments

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.

fencepost-error avatar Oct 06 '26 08:10 fencepost-error

@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.