mirror of
https://github.com/golang/go
synced 2024-11-21 23:24:41 -07:00
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
This commit is contained in:
parent
964309e2fd
commit
82a6a4f39e
@ -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*
|
||||
|
Loading…
Reference in New Issue
Block a user