main.mx raw

   1  // Regression: type-descriptor field offsets were built with 64-bit pointer
   2  // sizes on the wasm32 target.
   3  //
   4  // A struct containing a pointer (string, slice, func value) got a descriptor
   5  // whose field offsets assumed 8-byte pointers. A value returned across a
   6  // package boundary goes through the structural codec, which walks that
   7  // descriptor - so on wasm every field after the first was written at the
   8  // 64-bit offset and the caller read the 32-bit slot: zero, or the wrong word.
   9  // Within a single package the call is direct and the codec is not involved,
  10  // which is why only the cross-package case shows the mismatch.
  11  //
  12  // Fixed in: _mxc_stage4/ir_descriptors.mx (descPtrSize, typeDescSize,
  13  // typeDescAlign). Legacy already reads the pointer size from LLVM's
  14  // TargetData, so both compilers now describe the target's layout.
  15  
  16  package main
  17  
  18  import "tests/regressions/should_compile/struct_field_offsets_wasm/lib"
  19  
  20  func main() {
  21  	w := lib.New(`["REQ","x"]`)
  22  	println("mw I:")
  23  	println(w.I)
  24  	println("mw S:")
  25  	println(w.S)
  26  	p := lib.NewPair("hi")
  27  	println("pair I:")
  28  	println(p.I)
  29  	println("pair S:")
  30  	println(p.S)
  31  	n := lib.NewIntFirst("hi")
  32  	println("intfirst I:")
  33  	println(n.I)
  34  	println("intfirst S:")
  35  	println(n.S)
  36  }
  37