[BoundsSafety] Introduce a notion of `this` for C
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Certain thread safety and bounds safety annotations in C need to reference other fields within the same structure. For example:
```C
struct f {
int n;
int *__counted_by(n) buf;
};
```
In C++, this provides a well-defined way to express such self-referential relationships. C has no equivalent, so the current implementation works around this limitation by allowing `DeclRefExpr` to refer directly to a `FieldDecl`.
This is semantically incorrect — `FieldDecl` should only be referenced via `MemberExpr`, never via `DeclRefExpr`. Introducing a C equivalent of `CXXThisExpr` would resolve this improper usage and provide a clean, principled foundation for self-referential annotations in C.
Proposed solution: Add a new AST node (e.g., `CThisExpr` or similar) that mirrors `CXXThisExpr` semantics for C, enabling bounds safety and thread safety annotations to correctly express field-to-field references within a struct.
Contributor guide
Assessment
This issue has not been assessed yet.