slice_pop_resize.mx raw

   1  // Regression: pop and resize aborted on every call in a stage4 build.
   2  //
   3  // The emitters called runtime.slicePanic with the condition as an argument and
   4  // no branch around it, but the runtime panic entries are unconditional: they
   5  // panic the moment they are entered. So pop() on a non-empty slice and
   6  // resize() within capacity both aborted, while legacy - which branches to a
   7  // fault block - was correct. They now call runtime.sliceCheckPop and
   8  // runtime.sliceCheckResize, entries that carry the test themselves.
   9  package main
  10  
  11  import "fmt"
  12  
  13  func main() {
  14  	s := []int32{:3}
  15  	s[0] = 7
  16  	s[1] = 8
  17  	s[2] = 9
  18  	if x := pop(s); x != 9 {
  19  		panic("pop returned the wrong element")
  20  	}
  21  
  22  	t := []int32{:0:8}
  23  	t = resize(t, 5)
  24  	if len(t) != 5 {
  25  		panic("resize did not set the length")
  26  	}
  27  	t = push(t, int32(4))
  28  	if len(t) != 6 {
  29  		panic("push after resize")
  30  	}
  31  	t[5] = 11
  32  	if t[5] != 11 {
  33  		panic("resized tail is not writable")
  34  	}
  35  
  36  	fmt.Println("ok")
  37  }
  38