Issue 241454
Summary [BoundsSafety] counted_by after the type specifier applies to the top-level pointer
Labels clang:bounds-safety
Assignees
Reporter rapidsna
    ```c
struct S {
  int n;
  int __attribute__((counted_by(n))) *p;  // accepted as 'int * __counted_by(n)'
};
```

A GNU counted_by-family attribute written after the type specifier should apply to the adjacent type (`int`) and be rejected, as `int [[clang::counted_by(n)]] *p` is. Only one written before the type specifier (`__counted_by(n) int *p`) should apply to the top-level pointer.

Clang currently can't tell the two positions apart: both end up in the DeclSpec attribute list. #233582 keeps the existing behavior, with FIXMEs referring to this issue in `SemaType.cpp` (`distributeBoundsAttrFromDeclSpec`) and in `clang/test/{Sema,AST}/attr-counted-by-struct-ptrs.c`.

Fixing it would reject code that compiles today, though little code is expected to rely on this form, I believe.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to