empty_select.mx raw

   1  // Regression: select {} emitted invalid IR.
   2  //
   3  // A select with no clauses emitted its block without a terminator, so the next
   4  // block's label followed with no branch and clang rejected the module
   5  // ("expected instruction opcode"). Legacy short-circuits an empty select in
   6  // createSelect: the blocking form blocks forever, which the runtime reports as
   7  // a deadlock, and the form whose only clause is default does nothing. stage4
   8  // now does the same - the blocking form reaches runtime.deadlock() and the
   9  // default form emits nothing.
  10  //
  11  // The blocking form is never called here: a program that reaches it panics.
  12  // Both compilers were checked by hand against it and print the same
  13  // "panic: runtime error at 0x...: deadlock", differing only in the address.
  14  // What this test holds down is the IR: the module has to compile, and the
  15  // default form has to run.
  16  package main
  17  
  18  func neverCalled() (r int32) {
  19  	select {}
  20  }
  21  
  22  func defaultOnly() {
  23  	select {
  24  	default:
  25  	}
  26  }
  27  
  28  func main() {
  29  	defaultOnly()
  30  	println("ok")
  31  }
  32