Skip to content

[BoundsSafety] Keep new function type if merged with implicit decl #10845

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

In BoundsSafety, we allow merging bounds attributes between function decls if the old decl is implicit. This enables us to add bounds attributes to a function decl if the old one is implicit without causing 'incompatible function decl' error. For example, we can redeclare the implicit decl of memcmp, and add __sized_by() attributes to its parameters.

In attribute-only mode, those attributes are sugars though, and compatible function decls are merged by Context.mergeTypes(), which drops those sugars. If both canonical types are the same, we can keep the new type to retain sugars.

rdar://152192125

In BoundsSafety, we allow merging bounds attributes between function
decls if the old decl is implicit. This enables us to add bounds
attributes to a function decl if the old one is implicit without causing
'incompatible function decl' error. For example, we can redeclare the
implicit decl of `memcmp`, and add `__sized_by()` attributes to its
parameters.

In attribute-only mode, those attributes are sugars though, and
compatible function decls are merged by `Context.mergeTypes()`, which
drops those sugars. If both canonical types are the same, we can keep
the new type to retain sugars.

rdar://152192125
@patrykstefanski patrykstefanski added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label Jun 13, 2025
@patrykstefanski
Copy link
Author

@swift-ci test llvm

@hnrklssn
Copy link

Are we planning to make mergeTypes not drop the sugar types in the future, or is this a permanent fix?

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