File tree 2 files changed +31
-1
lines changed
src/cmd/compile/internal/staticinit 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -881,7 +881,13 @@ func mayModifyPkgVar(n ir.Node) bool {
881
881
// safeLHS reports whether the assigned-to variable lhs is either a
882
882
// local variable or a global from another package.
883
883
safeLHS := func (lhs ir.Node ) bool {
884
- v , ok := ir .OuterValue (lhs ).(* ir.Name )
884
+ outer := ir .OuterValue (lhs )
885
+ // "*p = ..." should be safe if p is a local variable.
886
+ // TODO: Should ir.OuterValue handle this?
887
+ for outer .Op () == ir .ODEREF {
888
+ outer = outer .(* ir.StarExpr ).X
889
+ }
890
+ v , ok := outer .(* ir.Name )
885
891
return ok && v .Op () == ir .ONAME && ! (v .Class == ir .PEXTERN && v .Sym ().Pkg == types .LocalPkg )
886
892
}
887
893
Original file line number Diff line number Diff line change
1
+ // asmcheck
2
+
3
+ // Copyright 2024 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package p
8
+
9
+ var x = func () int {
10
+ n := 0
11
+ f (& n )
12
+ return n
13
+ }()
14
+
15
+ func f (p * int ) {
16
+ * p = 1
17
+ }
18
+
19
+ var y = 1
20
+
21
+ // z can be static initialized.
22
+ //
23
+ // amd64:-"MOVQ"
24
+ var z = y
You can’t perform that action at this time.
0 commit comments