Skip to content

Commit fcab480

Browse files
committed
docs(rt): Document pointer transmute behavior
1 parent 8ef12df commit fcab480

File tree

1 file changed

+22
-0
lines changed
  • kmir/src/kmir/kdist/mir-semantics/rt

1 file changed

+22
-0
lines changed

kmir/src/kmir/kdist/mir-semantics/rt/data.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,28 @@ What can be supported without additional layout consideration is trivial casts b
13931393
requires lookupTy(TY_SOURCE) ==K lookupTy(TY_TARGET)
13941394
```
13951395

1396+
Transmuting a pointer to an integer discards provenance and reinterprets the pointer’s offset as a value of the target integer type.
1397+
1398+
```k
1399+
// `prove-rs/interior-mut3.rs` needs this
1400+
// TODO: check its correctness, I assume the pointer offset is the address here and we can use it to recover the PtrLocal
1401+
rule <k> #cast(
1402+
PtrLocal(_, _, _, metadata(_, PTR_OFFSET, _)),
1403+
castKindTransmute,
1404+
_TY_SOURCE,
1405+
TY_TARGET
1406+
)
1407+
=>
1408+
#intAsType(
1409+
PTR_OFFSET,
1410+
#bitWidth(#numTypeOf(lookupTy(TY_TARGET))),
1411+
#numTypeOf(lookupTy(TY_TARGET))
1412+
)
1413+
...
1414+
</k>
1415+
requires #isIntType(lookupTy(TY_TARGET))
1416+
```
1417+
13961418
Other `Transmute` casts that can be resolved are round-trip casts from type A to type B and then directly back from B to A.
13971419
The first cast is reified as a `thunk`, the second one resolves it and eliminates the `thunk`:
13981420

0 commit comments

Comments
 (0)