Counted by typeloc downstream#12925
Open
hnrklssn wants to merge 2 commits intoswiftlang:nextfrom
Open
Conversation
Cherry-pick of llvm#167287 adapted to the downstream fork. Populate BoundsAttributedTypeLoc with the attribute's source range so that diagnostics for incomplete pointee types can emit accurate fix-it hints (e.g. suggesting __sized_by instead of __counted_by). Previously the TypeLoc carried no data and source ranges were approximated from the count expression. Key changes: - BoundsAttributedLocInfo now stores a SourceRange - BoundsAttributedTypeLoc gains setAttrRange/getAttrRange, getAttrNameAsWritten, getAttrNameRange, and getLocalSourceRange - handleCountedByAttrField builds proper TypeSourceInfo via TypeLocBuilder - TransformCountAttributedType propagates attrRange - EmitIncompleteCountedByPointeeNotes uses TypeLoc for fix-its, with SourceRangeFor as fallback for BoundsSafety-specific callers - TypeLocFinder visitor extracts TypeLoc from expressions Additional fixes beyond the upstream PR: - Null safety in getTSI() and TypeLocFinder visitor methods - getLocalSourceRange() on BoundsAttributedTypeLoc to prevent infinite recursion through TypeLocRanger
…stics Replace the heuristic SourceRangeFor() implementation which reverse- engineered attribute source ranges by scanning backwards from the count expression with the Lexer, with a TypeLoc-based approach now that counted_by has a TypeLoc. To help with this we introduce Sema::TypeLocSource, a small wrapper with factory methods (fromAssignee, fromParameter, fromExpression, fromReturnType) that resolve the appropriate TypeLoc for each context. This lets BoundsSafetyCheckAssignmentToCountAttrPtr receive a pre-resolved TypeLoc rather than containing a bunch of special cased logic to extract TypeLocs for various scenarios. Additional changes: - Add VisitImplicitCastExpr, VisitUnaryDeref, VisitArraySubscriptExpr to TypeLocFinder so that subscript and dereference expressions resolve to the underlying declaration's TypeLoc - Extract getCountAttributedTypeLoc() helper for walking through pointer and function-return TypeLoc layers - Remove SourceRangeFor() and its ~100 lines of fragile Lexer scanning - Source locations now point to the attribute token start rather than the count expression position The SourceRangeFor fallback is removed because all known call paths now provide a TypeLoc via TypeLocSource. When TypeLoc resolution fails (e.g. unhandled expression types), the "consider using __sized_by" note is silently suppressed rather than emitted at an approximate location.
Member
Author
|
@swift-ci please test llvm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This cherry-picks llvm#167287 and makes adjustments to remove the current lexer-based approach for finding source ranges.