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

[BoundsSafety] Introduce a notion of `this` for C

Open rapidsna opened this issue 6 months ago • 2 comments

Certain thread safety and bounds safety annotations in C need to reference other fields within the same structure. For example:

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.

rapidsna avatar May 12 '26 17:05 rapidsna

Hey, can i work on this issue?

Caryoake avatar May 22 '26 07:05 Caryoake

Blocked by https://github.com/swiftlang/llvm-project/issues/13568

rapidsna avatar Jul 29 '26 21:07 rapidsna