Skip to content

Miri reports UB with simd_bitmask in sse impl #264

@Noratrieb

Description

@Noratrieb

To reproduce: cargo miri test -F allow-non-simd

test numberparse::correct::test::bad_dot ... error: Undefined Behavior: each element of a SIMD mask must be all-0-bits or all-1-bits
    --> /home/nilsh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs:1381:5
     |
1381 |     simd_bitmask::<_, u16>(a.as_i8x16()) as u32 as i32
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ each element of a SIMD mask must be all-0-bits or all-1-bits
     |
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
     = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
     = note: BACKTRACE:
     = note: inside `std::arch::x86_64::_mm_movemask_epi8` at /home/nilsh/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/sse2.rs:1381:5: 1381:41
     = note: inside `simdutf8::implementation::x86::sse42::<impl simdutf8::implementation::helpers::SimdU8Value<std::arch::x86_64::__m128i>>::is_ascii` at /home/nilsh/.cargo/registry/src/github.com-1ecc6299db9ec823/simdutf8-0.1.4/src/implementation/x86/sse42.rs:212:9: 212:34
     = note: inside `simdutf8::implementation::x86::sse42::SimdInput::is_ascii` at /home/nilsh/.cargo/registry/src/github.com-1ecc6299db9ec823/simdutf8-0.1.4/src/implementation/algorithm.rs:547:17: 547:29
     = note: inside `simdutf8::implementation::x86::sse42::<impl simdutf8::implementation::helpers::Utf8CheckAlgorithm<simdutf8::implementation::helpers::SimdU8Value<std::arch::x86_64::__m128i>>>::check_utf8` at /home/nilsh/.cargo/registry/src/github.com-1ecc6299db9ec823/simdutf8-0.1.4/src/implementation/algorithm.rs:175:20: 175:36
     = note: inside `<simdutf8::basic::imp::x86::sse42::ChunkedUtf8ValidatorImp as simdutf8::basic::imp::ChunkedUtf8Validator>::update_from_chunks` at /home/nilsh/.cargo/registry/src/github.com-1ecc6299db9ec823/simdutf8-0.1.4/src/implementation/algorithm.rs:476:21: 476:53
note: inside `Deserializer::<'_>::find_structural_bits`
    --> src/lib.rs:623:13
     |
623  |             utf8_validator.update_from_chunks(&tmpbuf);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `Deserializer::<'_>::from_slice_with_buffers`
    --> src/lib.rs:496:22
     |
496  |             unsafe { Self::find_structural_bits(input) };
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `Deserializer::<'_>::from_slice_with_buffer`
    --> src/lib.rs:462:9
     |
462  |         Self::from_slice_with_buffers(input, &mut buffer, string_buffer)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `Deserializer::<'_>::from_slice`
    --> src/lib.rs:442:9
     |
442  |         Self::from_slice_with_buffer(input, &mut string_buffer)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `value::owned::to_value`
    --> src/value/owned.rs:47:11
     |
47   |     match Deserializer::from_slice(s) {
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `numberparse::correct::test::to_value_from_str`
    --> src/numberparse/correct.rs:383:9
     |
383  |         to_value(val)
     |         ^^^^^^^^^^^^^
note: inside `numberparse::correct::test::bad_dot`
    --> src/numberparse/correct.rs:464:17
     |
464  |         assert!(to_value_from_str("1.").is_err());
     |                 ^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/numberparse/correct.rs:463:18
     |
462  |     #[test]
     |     ------- in this procedural macro expansion
463  |     fn bad_dot() {
     |                  ^
     = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions