// var vauto *[...]t = new([...]t)
// 4. copy the static array to the auto array
// *vauto = vstat
- // 5. assign slice of allocated heap to var
- // var = [0:]*auto
- // 6. for each dynamic part assign to the slice
- // var[i] = dynamic part
+ // 5. for each dynamic part assign to the array
+ // vauto[i] = dynamic part
+ // 6. assign slice of allocated heap to var
+ // var = vauto[:]
//
// an optimization is done if there is no constant part
// 3. var vauto *[...]t = new([...]t)
- // 5. var = [0:]*auto
- // 6. var[i] = dynamic part
+ // 5. vauto[i] = dynamic part
+ // 6. var = vauto[:]
// if the literal contains constants,
// make static initialized array (1),(2)
init.Append(a)
}
- // make slice out of heap (5)
- a = Nod(OAS, var_, Nod(OSLICE, vauto, Nod(OKEY, nil, nil)))
-
- a = typecheck(a, Etop)
- a = orderstmtinplace(a)
- a = walkstmt(a)
- init.Append(a)
- // put dynamics into slice (6)
+ // put dynamics into array (5)
for _, r := range n.List.Slice() {
if r.Op != OKEY {
Fatalf("slicelit: rhs not OKEY: %v", r)
}
index := r.Left
value := r.Right
- a := Nod(OINDEX, var_, index)
+ a := Nod(OINDEX, vauto, index)
a.Bounded = true
// TODO need to check bounds?
continue
}
- // build list of var[c] = expr
+ // build list of vauto[c] = expr
setlineno(value)
a = Nod(OAS, a, value)
a = walkstmt(a)
init.Append(a)
}
+
+ // make slice out of heap (6)
+ a = Nod(OAS, var_, Nod(OSLICE, vauto, Nod(OKEY, nil, nil)))
+
+ a = typecheck(a, Etop)
+ a = orderstmtinplace(a)
+ a = walkstmt(a)
+ init.Append(a)
}
func maplit(ctxt int, n *Node, var_ *Node, init *Nodes) {
p.s = p.s[8:9] // ERROR "write barrier"
*x = (*x)[3:5] // ERROR "write barrier"
}
+
+func f19(x, y *int, i int) int {
+ // Constructing a temporary slice on the stack should not
+ // require any write barriers. See issue 14263.
+ a := []*int{x, y} // no barrier
+ return *a[i]
+}
+
+func f20(x, y *int, i int) []*int {
+ // ... but if that temporary slice escapes, then the
+ // write barriers are necessary.
+ a := []*int{x, y} // ERROR "write barrier"
+ return a
+}