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

Wrong/misleading diagnostic in matrixmultiply==0.3.2 #2127

Closed
saethlin opened this issue May 19, 2022 · 4 comments · Fixed by #2128
Closed

Wrong/misleading diagnostic in matrixmultiply==0.3.2 #2127

saethlin opened this issue May 19, 2022 · 4 comments · Fixed by #2128

Comments

@saethlin
Copy link
Member

In matrixmultiply==0.3.2, running

MIRIFLAGS="-Zmiri-track-pointer-tag=191545 -Zmiri-tag-raw-pointers" cargo miri test test_dgemm

I currently see this, which I find confusing:

error: Undefined Behavior: attempting a read access using <191545> at alloc75350[0x88], but that tag does not exist in the borrow stack for this location
   --> /tmp/matrixmultiply-0.3.2/src/dgemm_kernel.rs:810:5
    |
810 |     *ptr.offset(i as isize)
    |     ^^^^^^^^^^^^^^^^^^^^^^^
    |     |
    |     attempting a read access using <191545> at alloc75350[0x88], but that tag does not exist in the borrow stack for this location
    |     this error occurs as part of an access at alloc75350[0x88..0x90]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <191545> was created by a retag at offsets [0x80..0x108]
   --> /tmp/matrixmultiply-0.3.2/src/gemm.rs:412:67
    |
412 |                     masked_kernel::<_, K>(kc, alpha, &*app.ptr(), &*bpp.ptr(),
    |                                                                   ^^^^^^^^^^^

The only tag-tracking message we get is for the tag creation. So from this I would assume that the pointer should be valid for accesses at offset 0x88, but it must not be because we have an error.

I stuck a println!("{:?}", place) in when the tag is created and I see this:

MPlaceTy { mplace: MemPlace { ptr: 0x1cb7f0[alloc75350]<191544>, align: Align(8 bytes), meta: None }, layout: TyAndLayout { ty: f64, layout: Layout { fields: Primitive, variants: Single { index: 0 }, abi: Scalar(Initialized { value: F64, valid_range: 0..=18446744073709551615 }), largest_niche: None, align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, size: Size(8 bytes) } } }

which I think means that this is just a pointer to f64, so I'm really confused as to why it looks like size_and_align_of_mplace is coming up with a much larger size.

@RalfJung
Copy link
Member

Usually when there is no invalidation message that means the pointer is used outside the range the tag was created for.

What does the tag creation tracking message say? The "help" seems to indicate the range is big enough...

which I think means that this is just a pointer to f64, so I'm really confused as to why it looks like size_and_align_of_mplace is coming up with a much larger size.

It certainly doesn't; the larger size must be coming from something else.
Note that the final error is consistent with the tag being created just for 8 bytes at [0x80..0x88], so my current guess would be that "was created by a retag at offsets [0x80..0x108]" is lying.

@saethlin
Copy link
Member Author

saethlin commented May 19, 2022

The tag-tracking messages just say this:

test test_dgemm ... note: tracking was triggered
   --> /tmp/matrixmultiply-0.3.2/src/gemm.rs:412:67
    |
412 |                     masked_kernel::<_, K>(kc, alpha, &*app.ptr(), &*bpp.ptr(),
    |                                                                   ^^^^^^^^^^^ created tag 191545
    |
    = note: inside closure at /tmp/matrixmultiply-0.3.2/src/gemm.rs:412:67

plus a backtrace, which is in my experience not helpful when the actual retag is in a local crate.

@RalfJung
Copy link
Member

FWIW, what does the diagnostic look like with #2128 ?

@saethlin
Copy link
Member Author

error: Undefined Behavior: attempting a read access using <191545> at alloc75350[0x88], but that tag does not exist in the borrow stack for this location
   --> /tmp/matrixmultiply-0.3.2/src/dgemm_kernel.rs:810:5
    |
810 |     *ptr.offset(i as isize)
    |     ^^^^^^^^^^^^^^^^^^^^^^^
    |     |
    |     attempting a read access using <191545> at alloc75350[0x88], but that tag does not exist in the borrow stack for this location
    |     this error occurs as part of an access at alloc75350[0x88..0x90]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <191545> was created by a retag at offsets [0x80..0x88]
   --> /tmp/matrixmultiply-0.3.2/src/gemm.rs:412:67
    |
412 |                     masked_kernel::<_, K>(kc, alpha, &*app.ptr(), &*bpp.ptr(),
    |                                                                   ^^^^^^^^^^^

@bors bors closed this as completed in 9230b92 May 19, 2022
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

Successfully merging a pull request may close this issue.

2 participants