From 82a6a4f39ed3fb78e49122a93c32998a5bcd0624 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 20 Dec 2011 16:25:57 -0500 Subject: [PATCH] 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 --- src/cmd/gc/subr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 07f97da2de..96616d88ee 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -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* -- 2.50.0