From: Matthew Dempsky Date: Sun, 27 Dec 2020 19:26:12 +0000 (-0800) Subject: [dev.regabi] cmd/compile: check for recursive import in ImportBody X-Git-Tag: go1.17beta1~1539^2~200 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=76136be027;p=gostls13.git [dev.regabi] cmd/compile: check for recursive import in ImportBody After earlier importer refactorings, most of the importer is now reentrant, so we don't need to guard against it at Resolve. The only remaining part that is still not reentrant is inline body importing, so move the recursive-import check there. Passes toolstash -cmp. Change-Id: Ia828f880a03e6125b102668c12a155d4c253d26b Reviewed-on: https://go-review.googlesource.com/c/go/+/280515 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index cf2cf87492..546ddcba79 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -71,7 +71,12 @@ func ImportBody(fn *ir.Func) { base.Fatalf("missing import reader for %v", fn) } + if inimport { + base.Fatalf("recursive inimport") + } + inimport = true r.doInline(fn) + inimport = false } func importReaderFor(sym *types.Sym, importers map[*types.Sym]iimporterAndOffset) *importReader { diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index dabfee3bf9..e23c249ff2 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -251,13 +251,7 @@ func Resolve(n ir.Node) (res ir.Node) { } } - if inimport { - base.Fatalf("recursive inimport") - } - inimport = true - n = expandDecl(n) - inimport = false - return n + return expandDecl(n) } r := ir.AsNode(n.Sym().Def)