Skip to content
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

simd_runtime_generate! creates implicit unsafe fn, allowing unsafe ops in seemingly safe code #34

Open
jonas-schievink opened this issue Jun 28, 2020 · 3 comments

Comments

@jonas-schievink
Copy link
Contributor

This program has undefined behavior but does not use unsafe:

extern crate simdeez;

use simdeez::avx2::*;
use simdeez::scalar::*;
use simdeez::sse2::*;
use simdeez::sse41::*;

simd_runtime_generate! {
    fn unsafe_deref(p: *const u8) -> u8 {
        *p
    }
}

fn main() {
    unsafe_deref_runtime_select(6 as *const u8);
}
@jackmott
Copy link
Collaborator

Good point, the macros should probably create unsafe functions, since all the intrinsics are unsafe. Do you agree with that as the solution?

@jonas-schievink
Copy link
Contributor Author

Most methods it creates are already unsafe, just not the runtime_select one. Making that unsafe as well would avoid this issue, so that seems fine.

I think there's a deeper issue with the fn unsafe_deref being sort of magically made into an unsafe fn though. I see this is needed to use pretty much any part of this library since so much is unsafe due to the use of the SIMD intrinsics, so I'm not sure how to solve that.

@verpeteren
Copy link

@jonas-schievink : can you check this PR/branch and check if that does what you requested+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants