Skip to content

Commit

Permalink
cmd/compile: fix static init of literal contains dynamic exprs
Browse files Browse the repository at this point in the history
Fixes golang#52673

Change-Id: Ib2faa5a669c05778fc6beb38c3e63d558af9b2be
Reviewed-on: https://go-review.googlesource.com/c/go/+/403995
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
Reviewed-by: David Chase <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
  • Loading branch information
cuonglm committed May 5, 2022
1 parent ed462a6 commit 0bd7408
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cmd/compile/internal/walk/complit.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,16 @@ func fixedlit(ctxt initContext, kind initKind, n *ir.CompLitExpr, var_ ir.Node,
case ir.OSLICELIT:
value := value.(*ir.CompLitExpr)
if (kind == initKindStatic && ctxt == inNonInitFunction) || (kind == initKindDynamic && ctxt == inInitFunction) {
slicelit(ctxt, value, a, init)
var sinit ir.Nodes
slicelit(ctxt, value, a, &sinit)
if kind == initKindStatic {
// When doing static initialization, init statements may contain dynamic
// expression, which will be initialized later, causing liveness analysis
// confuses about variables lifetime. So making sure those expressions
// are ordered correctly here. See issue #52673.
orderBlock(&sinit, map[string][]*ir.Name{})
}
init.Append(sinit...)
continue
}

Expand Down
16 changes: 16 additions & 0 deletions test/fixedbugs/issue52673.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// compile

// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package p

func f() {
var x string
func() [10][]bool {
return [10][]bool{
[]bool{bool(x < "")},
[]bool{}, []bool{}, []bool{}, []bool{}}
}()
}

0 comments on commit 0bd7408

Please sign in to comment.