[BoundsSafety] Extract diagnostics from ConstructDynamicBoundType / ConstructCountAttributedType / ConstructDynamicRangePointerType
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
Description
The CRTP TypeVisitor classes ConstructDynamicBoundType, ConstructCountAttributedType, and ConstructDynamicRangePointerType in SemaDeclAttr.cpp walk the type to a nested level index and construct the bounds-attributed type there, mixing type construction with diagnostics.
Extract diagnostics into flat functions that run before construction. After extraction, the conditions that currently trigger diagnostics become invariants enforced by assert().
Why
The new late parsing approach constructs types via TreeTransform replacement rather than these index-based visitors. However, the original construction is still needed for APINotes and template instantiation. Extracting diagnostics makes them callable independently from both the old and new code paths.
Note: This migration is not strictly necessary for T10. Another possible path is to create a separate diagnostic function for T10 and then refactor afterwards, in case it's going to block T10.
Key files
clang/lib/Sema/SemaDeclAttr.cpp—ConstructDynamicBoundType,ConstructCountAttributedType,ConstructDynamicRangePointerType
Validation
All existing lit tests must pass. No new diagnostics or diagnostic regressions — the extracted functions should produce identical diagnostic output.
Hi @rapidsna, I'm putting a patch together for this issue, may I submit a PR for this later this week?