funcvar_call.mx raw

   1  // Regression: extractvalue {ptr,ptr} on ptr function pointer.
   2  //
   3  // When a function was stored in a local variable and later called, the
   4  // stage4 emitter's emitCall function assumed all indirect call targets
   5  // were {ptr,ptr} closure structs. But a loaded function pointer is a bare
   6  // ptr. The emitter generated extractvalue {ptr,ptr} on a ptr-typed value,
   7  // producing: "error: '%t48' defined with type 'ptr' but expected
   8  // '{ ptr, ptr }'" from clang.
   9  //
  10  // Reproduces: store a function in a variable, then call it.
  11  // Fixed in: pkg/emit/calls.mx (SSAType-based needsExtract check).
  12  
  13  package main
  14  
  15  func greet() {
  16  	println("hello")
  17  }
  18  
  19  func main() {
  20  	f := greet
  21  	f()
  22  }
  23