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

[BoundsSafety] Investigate feasibility of independently migrating non-late-parsed counted_by/ended_by as type attributes

Open rapidsna opened this issue 7 months ago • 7 comments

Part of: Late Parsing Refactoring for Bounds Safety Type Attributes (see llvm/llvm-project#179612) Phase: 0 (no dependencies, can be done immediately) Type: Downstream refactoring (needs investigation)

Description

Currently both late-parsed and non-late-parsed paths for counted_by/ended_by go through SemaDeclAttr.cpp (declaration attribute handling). Move the non-late-parsed path to SemaType.cpp (type attribute handling), while the late-parsed path remains in SemaDeclAttr.cpp until the full mechanism switch (T10).

This task needs investigation on whether the non-late-parsed path can be moved independently. If not feasible as a standalone change, it will be absorbed into T10.

Why

The new approach treats these as type attributes, not declaration attributes. Migrating the non-late-parsed path first reduces the scope of the final mechanism switch.

Key files

  • clang/lib/Sema/SemaDeclAttr.cpp — handlePtrCountedByEndedByAttr, handleCountedByAttrField
  • clang/lib/Sema/SemaType.cpp — target location for type attribute handling

Validation

All existing lit tests must pass. Diagnostic output must be unchanged.

rapidsna avatar Apr 14 '26 18:04 rapidsna

Taking this one. I'll start with the standalone-feasibility check to see counted_by/ended_by path can be moved to SemaType.cpp on its own, or has to fold into T10 — and report back before sending a patch.

abhijeetsharma200 avatar Jun 26 '26 20:06 abhijeetsharma200

@abhijeetsharma200 Thank you!

rapidsna avatar Jun 26 '26 21:06 rapidsna

Looked into this. Under -fbounds-safety, these attrs are always token-cached and applied after the decl exists (ActOnFinishDelayedAttribute → handleCountedByAttrField), so nothing reaches processTypeAttrs as a ParsedAttr. So, handling them there needs either eagerly-parsed args or the LateParsedAttrType placeholder, i.e. T9/T10. And the early-available cases would skip the decl-side checks, whose relocation is the T5/T2/T11 chain T10 already depends on.

So my read is this folds into T10. Does that sound right, or do you see a standalone angle I'm missing?

abhijeetsharma200 avatar Jul 02 '26 23:07 abhijeetsharma200

@abhijeetsharma200 Thanks for looking into this!

Just to make sure I understand you correctly:

And the early-available cases would skip the decl-side checks, whose relocation is the T5/T2/T11 chain T10 already depends on.

You mean this work will require and depend on the refactoring work to separate out type and decl-side checks and trigger them from the right place? If so, yes, that sounds right to me.

rapidsna avatar Jul 02 '26 23:07 rapidsna

Yes, we are on the same page. So given this I think we should do this in T10. In the meantime can I pickup T5?

abhijeetsharma200 avatar Jul 03 '26 00:07 abhijeetsharma200

Yes, we are on the same page. So given this I think we should do this in T10. In the meantime can I pickup T5?

We're currently working on this locally, so it would be best to hold off for now to avoid conflicts or duplicated effort. We'll share an updated plan soon — you'll be able to pick up work from there.

rapidsna avatar Jul 05 '26 19:07 rapidsna

Closing by concluding that this task may not be done independently.

rapidsna avatar Jul 22 '26 23:07 rapidsna