[clang] [BoundsSafety] Support late parsing for `counted_by` in type positions (PR #166491)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 19 10:27:42 PST 2025


================
@@ -1161,10 +1161,13 @@ class Parser : public CodeCompletionHandler {
     IdentifierInfo *MacroII = nullptr;
     SourceLocation AttrNameLoc;
     SmallVector<Decl *, 2> Decls;
+    unsigned NestedTypeLevel;
----------------
AaronBallman wrote:

I think it's still an implementation detail though; only bounds safety cares about the pointer indirection level and I don't think [m]any other attributes will need it.

I think what I'm asking for here is whether we should make this a bit more clear in the interface. Currently, (outside of bounds safety) `LateParsedAttribute` is only used with declaration attributes and so it has `addDecl()` as a method so you can associate the late parsed attribute with each declaration it might be applied to. I would expect types and statements to follow the same general idea where there's a higher-level coupling associated with the late parsed attribute, rather than attribute-specific information like the pointer indirection level. e.g., perhaps the a different approach is to store two `QualType`s; one `QualType` is the full type of a type which potentially will be using an attributed type at some level and the other `QualType` is the type the attribute is actually written on. Then the pointer indirection level can be calculated by the bounds safety attributes rather than part of the more general interface for late parsed attributes. e.g., `int * [[foo]] * [[bar]] *` would have two late parsed attributes. The full `QualType` is the same for each and is `int ***`, but one `LateParsedAttribute` gets a `QualType` of `int **` (for `bar`) and the other gets `int *` (for `foo`).

But because we're expanding the capabilities here... Do we want `LateParsedDeclAttribute` and `LateParsedTypeAttribute` with the common stuff in a base class? Do we want a discriminated union in `LatestParsedAttribute` so only one of the decls, type, (or eventually smt) is valid at a time? My concern with the current approach is that it's unclear which fields are actually used under what circumstances,. e.g., you can get a `LatedParsedAttribute` which sets `PointerIndirectionLevel` but is actually for a declaration attribute rather than a type attribute.


https://github.com/llvm/llvm-project/pull/166491


More information about the cfe-commits mailing list