Skip to content

[-Wunsafe-buffer-usage] Relax passing to __counted_by_or_null() #11170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

patrykstefanski
Copy link

Relax restrictions when passing to
__counted_by_or_null()/__sized_by_or_null() parameters:

  • Allow the dependent count var to be anything.
  • Allow passing from non-null variant to *_or_null(), but do warn for passing *_or_null() to non-null variant.

rdar://156006635

@patrykstefanski patrykstefanski self-assigned this Aug 13, 2025
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Aug 13, 2025
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-156006635 branch from 1c9cc8d to f2adef0 Compare August 14, 2025 17:29
cb_int(cb, n);
// __counted_by_or_null(count) can have arbitrary count if the pointer is
// null. Since __counted_by() does not allow this, we diagnose
// __counted_by_or_null() -> __counted_by().

Choose a reason for hiding this comment

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

I meant as in emitting a note diagnostic

Relax restrictions when passing to
__counted_by_or_null()/__sized_by_or_null() parameters:
- Allow the dependent count var to be anything.
- Allow passing from non-null variant to *_or_null(), but do warn for
  passing *_or_null() to non-null variant.

rdar://156006635
@patrykstefanski patrykstefanski force-pushed the eng/pstefanski/PR-156006635 branch from f2adef0 to eee3ae8 Compare August 15, 2025 23:45
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.

2 participants