Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions kmir/src/kmir/kdist/mir-semantics/rt/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -1838,24 +1838,15 @@ the safety of this cast. The logic of the semantics and saftey of this cast for
```k
syntax MIRError ::= "#UBInvalidTransmuteMaybeUninit"
rule <k>
#cast( _VAL:Value , castKindTransmute , TY_FROM , TY_TO )
#cast( VAL:Value , castKindTransmute , _TY_FROM , TY_TO )
=>
#UBInvalidTransmuteMaybeUninit
Union(fieldIdx(1), Aggregate(variantIdx(0), ListItem(VAL) .List))
...
</k>
requires #isUnionType(lookupTy(TY_TO))
andBool #typeNameIs(lookupTy(TY_TO), "std::mem::MaybeUninit<")
andBool TY_FROM =/=K getFieldTy(#lookupMaybeTy(getFieldTy(lookupTy(TY_TO), 1)), 0)

rule <k>
#cast( VAL:Value , castKindTransmute , TY_FROM , TY_TO )
=>
Union( fieldIdx ( 1 ) , Aggregate ( variantIdx ( 0 ) , ListItem(VAL) .List ))
...
</k>
requires #isUnionType(lookupTy(TY_TO))
andBool #typeNameIs(lookupTy(TY_TO), "std::mem::MaybeUninit<")
andBool TY_FROM ==K getFieldTy(#lookupMaybeTy(getFieldTy(lookupTy(TY_TO), 1)), 0)
// `MaybeUninit<T>` accepts arbitrary bit patterns, so any value can be
// reinterpreted into the union's initialized field.

// Converting static or dynamic sized array of `T` to array of `std::mem::MaybeUninit<T>`.
// FIXME: Might need to check sizes as this cast could come from transmute_unchecked
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

┌─ 1 (root, init)
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
│ span: 0
│ (77 steps)
├─ 3 (terminal)
│ #EndProgram ~> .K
│ function: main
┊ constraint: true
┊ subst: ...
└─ 2 (leaf, target, terminal)
#EndProgram ~> .K



Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::mem::MaybeUninit;
fn main() {
unsafe {
let maybe_unsigned = std::intrinsics::transmute::<i128, MaybeUninit::<u128>>(9999);
// Note different types ^^^^ ^^^^
assert!(maybe_unsigned.assume_init() == 9999);
}
}
2 changes: 1 addition & 1 deletion kmir/src/tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
'assert-inhabited-fail',
'iterator-simple',
'unions-fail',
'transmute-maybe-uninit-fail',
'transmute-maybe-uninit-i128',
'ptr-through-wrapper-fail',
'test_offset_from-fail',
'ref-ptr-cast-elem-fail',
Expand Down
Loading