From c57c0212ebf44b7896477177c8e35be79ff3a586 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 19 Aug 2020 23:01:58 -0700 Subject: [PATCH] cmd/compile: define starting block before opening html writer Opening the html writer can fail, and the failure printer wants to use the entry block's line number. So make sure we set up the entry block first. Fixes #40919 Change-Id: I4ffa2839b45a721bbaf04ff84418e8108fa1cc37 Reviewed-on: https://go-review.googlesource.com/c/go/+/249497 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 5d0098b4e6fa1..4124655b79141 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -338,6 +338,10 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.panics = map[funcLine]*ssa.Block{} s.softFloat = s.config.SoftFloat + // Allocate starting block + s.f.Entry = s.f.NewBlock(ssa.BlockPlain) + s.f.Entry.Pos = fn.Pos + if printssa { s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f, ssaDumpCFG) // TODO: generate and print a mapping from nodes to values and blocks @@ -345,9 +349,6 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.f.HTMLWriter.WriteAST("AST", astBuf) } - // Allocate starting block - s.f.Entry = s.f.NewBlock(ssa.BlockPlain) - // Allocate starting values s.labels = map[string]*ssaLabel{} s.labeledNodes = map[*Node]*ssaLabel{}