Commit 82a6a4f3 authored by Russ Cox's avatar Russ Cox

gc: allow use of unsafe.Pointer in generated code

The functions we generate to implement == on structs
or arrays may need to refer to unsafe.Pointer even in
safe mode, in order to handle unexported fields contained
in other packages' structs.

R=ken2
CC=golang-dev
https://golang.org/cl/5505046
parent 964309e2
......@@ -2487,6 +2487,7 @@ genhash(Sym *sym, Type *t)
Node *n, *fn, *np, *nh, *ni, *call, *nx, *na, *tfn;
Node *hashel;
Type *first, *t1;
int old_safemode;
int64 size;
if(debug['r'])
......@@ -2616,7 +2617,16 @@ genhash(Sym *sym, Type *t)
typecheck(&fn, Etop);
typechecklist(fn->nbody, Etop);
curfn = nil;
// Disable safemode while compiling this code: the code we
// generate internally can refer to unsafe.Pointer.
// In this case it can happen if we need to generate an ==
// for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer.
old_safemode = safemode;
safemode = 0;
funccompile(fn, 0);
safemode = old_safemode;
}
// Return node for
......@@ -2694,6 +2704,7 @@ geneq(Sym *sym, Type *t)
{
Node *n, *fn, *np, *neq, *nq, *tfn, *nif, *ni, *nx, *ny, *nrange;
Type *t1, *first;
int old_safemode;
int64 size;
if(debug['r'])
......@@ -2814,7 +2825,16 @@ geneq(Sym *sym, Type *t)
typecheck(&fn, Etop);
typechecklist(fn->nbody, Etop);
curfn = nil;
// Disable safemode while compiling this code: the code we
// generate internally can refer to unsafe.Pointer.
// In this case it can happen if we need to generate an ==
// for a struct containing a reflect.Value, which itself has
// an unexported field of type unsafe.Pointer.
old_safemode = safemode;
safemode = 0;
funccompile(fn, 0);
safemode = old_safemode;
}
static Type*
......
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