Commit f6fc0dd6 authored by Cherry Zhang's avatar Cherry Zhang

cmd/compile: update signature of runtime.memclr*

runtime.memclr* functions have signatures

func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
func memclrHasPointers(ptr unsafe.Pointer, n uintptr)

Update compiler's copy. Also teach gc/mkbuiltin.go to handle
unsafe.Pointer. The import statement and its support is not
really necessary, but just to make it look like real Go code.

Fixes #19185.

Change-Id: I251d02571fde2716d4727e31e04d56ec04b6f22a
Reviewed-on: https://go-review.googlesource.com/37257
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAustin Clements <austin@google.com>
parent d3d2a67c
......@@ -98,37 +98,37 @@ var runtimeDecls = [...]struct {
{"makeslice64", funcTag, 90},
{"growslice", funcTag, 91},
{"memmove", funcTag, 92},
{"memclrNoHeapPointers", funcTag, 93},
{"memclrHasPointers", funcTag, 93},
{"memequal", funcTag, 94},
{"memequal8", funcTag, 95},
{"memequal16", funcTag, 95},
{"memequal32", funcTag, 95},
{"memequal64", funcTag, 95},
{"memequal128", funcTag, 95},
{"int64div", funcTag, 96},
{"uint64div", funcTag, 97},
{"int64mod", funcTag, 96},
{"uint64mod", funcTag, 97},
{"float64toint64", funcTag, 98},
{"float64touint64", funcTag, 99},
{"float64touint32", funcTag, 101},
{"int64tofloat64", funcTag, 102},
{"uint64tofloat64", funcTag, 103},
{"uint32tofloat64", funcTag, 104},
{"complex128div", funcTag, 105},
{"racefuncenter", funcTag, 106},
{"memclrNoHeapPointers", funcTag, 94},
{"memclrHasPointers", funcTag, 94},
{"memequal", funcTag, 95},
{"memequal8", funcTag, 96},
{"memequal16", funcTag, 96},
{"memequal32", funcTag, 96},
{"memequal64", funcTag, 96},
{"memequal128", funcTag, 96},
{"int64div", funcTag, 97},
{"uint64div", funcTag, 98},
{"int64mod", funcTag, 97},
{"uint64mod", funcTag, 98},
{"float64toint64", funcTag, 99},
{"float64touint64", funcTag, 100},
{"float64touint32", funcTag, 102},
{"int64tofloat64", funcTag, 103},
{"uint64tofloat64", funcTag, 104},
{"uint32tofloat64", funcTag, 105},
{"complex128div", funcTag, 106},
{"racefuncenter", funcTag, 107},
{"racefuncexit", funcTag, 5},
{"raceread", funcTag, 106},
{"racewrite", funcTag, 106},
{"racereadrange", funcTag, 107},
{"racewriterange", funcTag, 107},
{"msanread", funcTag, 107},
{"msanwrite", funcTag, 107},
{"raceread", funcTag, 107},
{"racewrite", funcTag, 107},
{"racereadrange", funcTag, 108},
{"racewriterange", funcTag, 108},
{"msanread", funcTag, 108},
{"msanwrite", funcTag, 108},
}
func runtimeTypes() []*Type {
var typs [108]*Type
var typs [109]*Type
typs[0] = bytetype
typs[1] = typPtr(typs[0])
typs[2] = Types[TANY]
......@@ -222,20 +222,21 @@ func runtimeTypes() []*Type {
typs[90] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[88])})
typs[91] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[88]), anonfield(typs[32])}, []*Node{anonfield(typs[88])})
typs[92] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[49])}, nil)
typs[93] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[49])}, nil)
typs[94] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[49])}, []*Node{anonfield(typs[11])})
typs[95] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[11])})
typs[96] = functype(nil, []*Node{anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[15])})
typs[97] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])})
typs[98] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])})
typs[99] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])})
typs[100] = Types[TUINT32]
typs[101] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[100])})
typs[102] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])})
typs[103] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])})
typs[104] = functype(nil, []*Node{anonfield(typs[100])}, []*Node{anonfield(typs[13])})
typs[105] = functype(nil, []*Node{anonfield(typs[19]), anonfield(typs[19])}, []*Node{anonfield(typs[19])})
typs[106] = functype(nil, []*Node{anonfield(typs[49])}, nil)
typs[107] = functype(nil, []*Node{anonfield(typs[49]), anonfield(typs[49])}, nil)
typs[93] = Types[TUNSAFEPTR]
typs[94] = functype(nil, []*Node{anonfield(typs[93]), anonfield(typs[49])}, nil)
typs[95] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[49])}, []*Node{anonfield(typs[11])})
typs[96] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[11])})
typs[97] = functype(nil, []*Node{anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[15])})
typs[98] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])})
typs[99] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])})
typs[100] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])})
typs[101] = Types[TUINT32]
typs[102] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[101])})
typs[103] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])})
typs[104] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])})
typs[105] = functype(nil, []*Node{anonfield(typs[101])}, []*Node{anonfield(typs[13])})
typs[106] = functype(nil, []*Node{anonfield(typs[19]), anonfield(typs[19])}, []*Node{anonfield(typs[19])})
typs[107] = functype(nil, []*Node{anonfield(typs[49])}, nil)
typs[108] = functype(nil, []*Node{anonfield(typs[49]), anonfield(typs[49])}, nil)
return typs[:]
}
......@@ -12,6 +12,8 @@ package runtime
// emitted by compiler, not referred to by go programs
import "unsafe"
func newobject(typ *byte) *any
func panicindex()
func panicslice()
......@@ -129,8 +131,8 @@ func makeslice(typ *byte, len int, cap int) (ary []any)
func makeslice64(typ *byte, len int64, cap int64) (ary []any)
func growslice(typ *byte, old []any, cap int) (ary []any)
func memmove(to *any, frm *any, length uintptr)
func memclrNoHeapPointers(ptr *byte, length uintptr)
func memclrHasPointers(ptr *byte, length uintptr)
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
func memclrHasPointers(ptr unsafe.Pointer, n uintptr)
func memequal(x, y *any, size uintptr) bool
func memequal8(x, y *any) bool
......
......@@ -72,6 +72,12 @@ func mkbuiltin(w io.Writer, name string) {
}
fmt.Fprintf(w, "{%q, funcTag, %d},\n", decl.Name.Name, interner.intern(decl.Type))
case *ast.GenDecl:
if decl.Tok == token.IMPORT {
if len(decl.Specs) != 1 || decl.Specs[0].(*ast.ImportSpec).Path.Value != "\"unsafe\"" {
log.Fatal("runtime cannot import other package")
}
continue
}
if decl.Tok != token.VAR {
log.Fatal("unhandled declaration kind", decl.Tok)
}
......@@ -137,6 +143,11 @@ func (i *typeInterner) mktype(t ast.Expr) string {
return "runetype"
}
return fmt.Sprintf("Types[T%s]", strings.ToUpper(t.Name))
case *ast.SelectorExpr:
if t.X.(*ast.Ident).Name != "unsafe" || t.Sel.Name != "Pointer" {
log.Fatalf("unhandled type: %#v", t)
}
return "Types[TUNSAFEPTR]"
case *ast.ArrayType:
if t.Len == nil {
......
......@@ -419,13 +419,13 @@ func memclrrange(n, v1, v2, a *Node) bool {
n.Left = nod(ONE, nod(OLEN, a, nil), nodintconst(0))
// hp = &a[0]
hp := temp(ptrto(Types[TUINT8]))
hp := temp(Types[TUNSAFEPTR])
tmp := nod(OINDEX, a, nodintconst(0))
tmp.Bounded = true
tmp = nod(OADDR, tmp, nil)
tmp = nod(OCONVNOP, tmp, nil)
tmp.Type = ptrto(Types[TUINT8])
tmp.Type = Types[TUNSAFEPTR]
n.Nbody.Append(nod(OAS, hp, tmp))
// hn = len(a) * sizeof(elem(a))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment