Skip to content

Undefined behavior with unchecked target_feature calls #31

@Manishearth

Description

@Manishearth

bitmaps/src/bitmap.rs

Lines 691 to 701 in b449cec

impl From<Bitmap<128>> for __m128i {
fn from(data: Bitmap<128>) -> Self {
unsafe { data.load_m128i() }
}
}
impl From<Bitmap<256>> for __m256i {
fn from(data: Bitmap<256>) -> Self {
unsafe { data.load_m256i() }
}
}

This is UB: the two load functions are #[target_feature(enable = "avx")], which means they are not unconditionally available on all x86 platforms. This should probably check if cfg_feature_enabled!("avx") or use cfg!(target_feature = "avx2"). In the latter case, the avx calls will only be reached if compiling with AVX enabled (whereas in the former, you can have one binary for all x86 chips and there's a runtime check)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions