]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: update signature of runtime.memclr*
authorCherry Zhang <cherryyz@google.com>
Mon, 20 Feb 2017 04:40:24 +0000 (23:40 -0500)
committerCherry Zhang <cherryyz@google.com>
Tue, 28 Feb 2017 19:22:29 +0000 (19:22 +0000)
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: Austin Clements <austin@google.com>
src/cmd/compile/internal/gc/builtin.go
src/cmd/compile/internal/gc/builtin/runtime.go
src/cmd/compile/internal/gc/mkbuiltin.go
src/cmd/compile/internal/gc/range.go

index c43e3a0b6bfd4cdf0e709a0524ac5067c445467c..9f8aa2697bb42866b941e816cc59ffcd868bdc22 100644 (file)
@@ -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[:]
 }
index a6aae0c468877ae7c9fbe1c9aa42144cc185050b..fc55104ef803dd416b66ea1eddd466656747e135 100644 (file)
@@ -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
index 995f5be1df1e3c8dc5963615edf7cbce0329f25b..6d918f8d25346ec9df0ac0beb98e33f76b8139e0 100644 (file)
@@ -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 {
index d1ac5780a0480edd402221ef9e9b88bf1afecb04..9c57b7606bda01d3ba573bce3c4963802261e836 100644 (file)
@@ -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))