Skip to content

Conversation

@patrykstefanski
Copy link

Check safe assignment patterns. This uses the infrastructure that is already available for count-attributed arguments, and checks for each assigned pointer in the group that the RHS has enough elements.

rdar://161608493

@patrykstefanski patrykstefanski self-assigned this Oct 23, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Oct 23, 2025
Copy link
Member

@hnrklssn hnrklssn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than what I've commented on

@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-161608493 branch 2 times, most recently from a73715e to 77d721c Compare November 1, 2025 01:31
QualType Ty = VD->getType();
const auto *CAT = Ty->getAs<CountAttributedType>();
if (!CAT && Ty->isPointerType())
CAT = Ty->getPointeeType()->getAs<CountAttributedType>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests covering this case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those cases happen when we have a dereference on LHS (*ptr = ). We have tests like this:

void good_inout_span(int *__counted_by(*count) *p, size_t *count, std::span<int> sp) {
  *p = sp.data();
  *count = sp.size();
}


const BinaryOperator *Assign = Group.Assignments[I];

// TODO: Move this logic to isCountAttributedPointerArgumentSafeImpl.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the parameters of isCountAttributedPointerArgumentSafeImpl aren't the most intuitive. Technically, we do not need the caller to pass CountArg because the count expression with DependentValues already contain that information.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take care of this TODO in my refactoring patch.

@patrykstefanski
Copy link
Author

@swift-ci test llvm

Check safe assignment patterns. This uses the infrastructure that is
already available for count-attributed arguments, and checks for each
assigned pointer in the group that the RHS has enough elements.

rdar://161608493
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-161608493 branch from 77d721c to 12d943e Compare November 5, 2025 04:22
@patrykstefanski
Copy link
Author

@swift-ci test llvm

@patrykstefanski patrykstefanski merged commit cb7dcc9 into swiftlang:next Nov 5, 2025
0 of 2 checks passed
@patrykstefanski patrykstefanski deleted the eng/pstefanski/PR-161608493 branch November 5, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants