interp: add support for reading a pointer tag

This is necessary to get https://github.com/tinygo-org/tinygo/pull/3691
working.
This commit is contained in:
Ayke van Laethem
2023-05-20 17:28:13 +02:00
committed by Ron Evans
parent cf39db36fe
commit 481f60c5ea
3 changed files with 17 additions and 0 deletions
+8
View File
@@ -746,6 +746,14 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// src/strings/builder.go in the Go source tree. This is
// the identity operator, so we can return the input.
locals[inst.localIndex] = lhs
} else if inst.opcode == llvm.And && rhs.Uint() < 8 {
// This is probably part of a pattern to get the lower bits
// of a pointer for pointer tagging, like this:
// uintptr(unsafe.Pointer(t)) & 0b11
// We can actually support this easily by ANDing with the
// pointer offset.
result := uint64(lhsPtr.offset()) & rhs.Uint()
locals[inst.localIndex] = makeLiteralInt(result, int(lhs.len(r)*8))
} else {
// Catch-all for weird operations that should just be done
// at runtime.