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

Unexpected Alias type with -Z valid-value-checks #3113

Closed
adpaco-aws opened this issue Mar 27, 2024 · 1 comment
Closed

Unexpected Alias type with -Z valid-value-checks #3113

adpaco-aws opened this issue Mar 27, 2024 · 1 comment
Assignees
Labels
[C] Bug This is a bug. Something isn't working.

Comments

@adpaco-aws
Copy link
Contributor

#3085 introduced the following test in tests/kani/ValidValues/write_invalid.rs:

use std::num::NonZeroU8;

#[kani::proof]
#[kani::should_panic]
pub fn write_invalid_bytes_no_ub_with_spurious_cex() {
    let mut non_zero: NonZeroU8 = kani::any();
    let dest = &mut non_zero as *mut _;
    unsafe { std::intrinsics::write_bytes(dest, 0, 1) };
}

#[kani::proof]
#[kani::should_panic]
pub fn write_valid_before_read() {
    let mut non_zero: NonZeroU8 = kani::any();
    let mut non_zero_2: NonZeroU8 = kani::any();
    let dest = &mut non_zero as *mut _;
    unsafe { std::intrinsics::write_bytes(dest, 0, 1) };
    unsafe { std::intrinsics::write_bytes(dest, non_zero_2.get(), 1) };
    assert_eq!(non_zero, non_zero_2)
}

#[kani::proof]
#[kani::should_panic]
pub fn read_invalid_is_ub() {
    let mut non_zero: NonZeroU8 = kani::any();
    let dest = &mut non_zero as *mut _;
    unsafe { std::intrinsics::write_bytes(dest, 0, 1) };
    assert_eq!(non_zero.get(), 0)
}

In the toolchain upgrade in #3102 we're getting an unexpected compilation error for this test (CI run here) which looks like this:

unexpected type: Ty { id: 14, kind: Alias(Projection, AliasTy { def_id: AliasDef(DefId { id: 11, name: "std::num::ZeroablePrimitive::NonZeroInner" }), args: GenericArgs([Type(Ty { id: 3, kind: RigidTy(Uint(U8)) }), Const(Const { kind: Allocated(Allocation { bytes: [Some(1)], provenance: ProvenanceMap { ptrs: [] }, align: 1, mutability: Mut }), ty: Ty { id: 9, kind: RigidTy(Bool) }, id: ConstId(4) })]) }) }

And it's coming from this function:

2024-03-27T14:52:39.487676Z TRACE visit_fn{function=Instance { kind: Item, def: "_RINvNtCsbLQVFf8BMTJ_4core10intrinsics11write_bytesINtNtNtB4_3num7nonzero7NonZerohEECsi8ET5SPUdoh_13write_invalid", args: GenericArgs([Type(Ty { id: 6, kind: RigidTy(Adt(AdtDef(DefId { id: 6, name: "std::num::NonZero" }), GenericArgs([Type(Ty { id: 3, kind: RigidTy(Uint(U8)) })]))) }), Const(Const { kind: Allocated(Allocation { bytes: [Some(1)], provenance: ProvenanceMap { ptrs: [] }, align: 1, mutability: Mut }), ty: Ty { id: 9, kind: RigidTy(Bool) }, id: ConstId(4) })]) }}: kani_compiler::kani_middle::transform::check_values: transform function="std::intrinsics::write_bytes::<std::num::NonZero<u8>>"

with Kani version: 0.48.0

We're going to change the test to be a "fixme" test. We should first fix avoid returning an Alias from StableMIR, and then restore the test.

@adpaco-aws adpaco-aws added the [C] Bug This is a bug. Something isn't working. label Mar 27, 2024
@celinval celinval self-assigned this Mar 27, 2024
celinval added a commit to celinval/rust-dev that referenced this issue Mar 28, 2024
We were only instantiating before, which would leak an AliasTy.
I added a test case that reproduce the issue seen here:

model-checking/kani#3113
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 29, 2024
Normalize the result of `Fields::ty_with_args`

We were only instantiating before, which would leak an AliasTy. I added a test case that reproduce the issue seen here:

model-checking/kani#3113

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 29, 2024
Normalize the result of `Fields::ty_with_args`

We were only instantiating before, which would leak an AliasTy. I added a test case that reproduce the issue seen here:

model-checking/kani#3113

r? ``@oli-obk``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 29, 2024
Rollup merge of rust-lang#123176 - celinval:smir-field-ty, r=oli-obk

Normalize the result of `Fields::ty_with_args`

We were only instantiating before, which would leak an AliasTy. I added a test case that reproduce the issue seen here:

model-checking/kani#3113

r? ``@oli-obk``
tautschnig added a commit to tautschnig/kani that referenced this issue Apr 5, 2024
Changes required due to:
- rust-lang/rust@a325bce3cd Normalize the result of Fields::ty_with_args

Resolves: model-checking#3125, model-checking#3113
tautschnig added a commit that referenced this issue Apr 5, 2024
Changes required due to:
- rust-lang/rust@a325bce3cd Normalize the result of Fields::ty_with_args

Resolves: #3125, #3113
@tautschnig
Copy link
Member

Was fixed in #3127.

celinval pushed a commit to celinval/kani-dev that referenced this issue Apr 17, 2024
zpzigi754 pushed a commit to zpzigi754/kani that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Bug This is a bug. Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants