Skip to content

[BoundsSafety] Provide unsafe memcpy/memset for migration #10636

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
mxms0 opened this issue May 7, 2025 · 0 comments
Open

[BoundsSafety] Provide unsafe memcpy/memset for migration #10636

mxms0 opened this issue May 7, 2025 · 0 comments
Assignees
Labels
clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang

Comments

@mxms0
Copy link

mxms0 commented May 7, 2025

Proposal

Add __unsafe_memcpy/__unsafe_memset (and possibly others) to ptrcheck.h a la:

uint8_t* __unsafe_indexable __unsafe_memcpy(uint8_t* __unsafe_indexable dst, uint8_t* __unsafe_indexable src, size_t size) { 
  memcpy(__unsafe_forge_bidi_indexable(uint8_t*, dst, size),
         __unsafe_forge_bidi_indexable(uint8_t*, src, size),
         size);
}

Could also be a macro, I suppose :)

The general pattern I've been going with as part of adoption is to get everything building with -fbounds-safety by marking nearly everything ABI-changing as __unsafe_indexable. This makes it easier to make localized improvements while still being able to build and run tests.

They'd still be clearly marked as unsafe, and so they'd be easily searchable/identifiable.

This also makes #pragma clang abi_ptr_attr set(unsafe_indexable) more attainable, and easier to adopt on per-line, per-function, per-TU granularities.

This request is mostly an adoption/ergonomics proposal, and as mentioned in discord, a temporary workaround exists to put these unsafe functions in a local header for adoption.

@delcypher delcypher added the clang:bounds-safety Issue relating to the experimental -fbounds-safety feature in Clang label May 7, 2025
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

No branches or pull requests

3 participants