Skip to content

Commit 470f857

Browse files
committed
docs(rt): Document pointer transmute behavior
1 parent 596829b commit 470f857

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
@@ -1456,6 +1456,28 @@ What can be supported without additional layout consideration is trivial casts b
14561456
requires lookupTy(TY_SOURCE) ==K lookupTy(TY_TARGET)
14571457
```
14581458

1459+
Transmuting a pointer to an integer discards provenance and reinterprets the pointer’s offset as a value of the target integer type.
1460+
1461+
```k
1462+
// `prove-rs/interior-mut3.rs` needs this
1463+
// TODO: check its correctness, I assume the pointer offset is the address here and we can use it to recover the PtrLocal
1464+
rule <k> #cast(
1465+
PtrLocal(_, _, _, metadata(_, PTR_OFFSET, _)),
1466+
castKindTransmute,
1467+
_TY_SOURCE,
1468+
TY_TARGET
1469+
)
1470+
=>
1471+
#intAsType(
1472+
PTR_OFFSET,
1473+
#bitWidth(#numTypeOf(lookupTy(TY_TARGET))),
1474+
#numTypeOf(lookupTy(TY_TARGET))
1475+
)
1476+
...
1477+
</k>
1478+
requires #isIntType(lookupTy(TY_TARGET))
1479+
```
1480+
14591481
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.
14601482
The first cast is reified as a `thunk`, the second one resolves it and eliminates the `thunk`:
14611483

0 commit comments

Comments
 (0)