Issue |
141827
|
Summary |
Allow `counted_by` argument to support simple arithmetic expressions
|
Labels |
new issue
|
Assignees |
|
Reporter |
seanm
|
Consider the following C:
```c
struct mystruct
{
unsigned len;
unsigned data[] __attribute__((counted_by(len)));
};
```
This works with recent clang.
But it would be nice if simple arithmetic expressions could be used in the `counted_by` argument, like `counted_by(len - 1)` or `counted_by(len * 4)`, things like that. Trying to do so gives:
```
<source>:4:47: error: 'counted_by' argument must be a simple declaration reference
4 | unsigned data[] __attribute__((counted_by(len - 1)));
| ^~~~~~~
```
See: https://godbolt.org/z/sx6sY1fjG
The gcc folks seemed to consider this too: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896#c36 though from godbolt it seems they don't support it either.
There are several places in the libusb codebase that would benefit from this. The most complicated case would be `counted_by((len - 2) / 2)`.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs