<div dir="ltr"><div>Hi all,  <br></div><div><br></div><div>I was testing panama on java 19 with my work issued macbook pro, and my varargs method bindings were returning invalid data.</div><div><br></div><div>I thought that maybe it was a failure in my own code, but I couldn't work around it so I created a test instance using manually written code: <br></div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(212,212,212)">  test(</span><span style="color:rgb(206,145,120)">"manual varargs"</span><span style="color:rgb(212,212,212)">) {</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">val</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">linker</span><span style="color:rgb(212,212,212)"> = </span><span style="color:rgb(78,201,176)">Linker</span><span style="color:rgb(212,212,212)">.nativeLinker().nn</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">val</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">sl</span><span style="color:rgb(212,212,212)"> = </span><span style="color:rgb(78,201,176)">SymbolLookup</span><span style="color:rgb(212,212,212)">.loaderLookup().nn</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">val</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">mh</span><span style="color:rgb(212,212,212)"> = linker</span></div><div><span style="color:rgb(212,212,212)">      .downcallHandle(</span></div><div><span style="color:rgb(212,212,212)">        sl.lookup(</span><span style="color:rgb(206,145,120)">"add_var"</span><span style="color:rgb(212,212,212)">).nn.orElseThrow(),</span></div><div><span style="color:rgb(212,212,212)">        </span><span style="color:rgb(78,201,176)">FunctionDescriptor</span><span style="color:rgb(212,212,212)">.of(</span><span style="color:rgb(78,201,176)">JAVA_INT</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(78,201,176)">JAVA_INT</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(78,201,176)">JAVA_INT</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(78,201,176)">JAVA_INT</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">      )</span></div><div><span style="color:rgb(212,212,212)">      .nn;</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">val</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">res</span><span style="color:rgb(212,212,212)"> = </span><span style="color:rgb(78,201,176)">MethodHandleFacade</span><span style="color:rgb(212,212,212)">.callVariadic(mh, </span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(212,212,212)">).</span><span style="color:rgb(220,220,170)">asInstanceOf</span><span style="color:rgb(212,212,212)">[</span><span style="color:rgb(78,201,176)">Int</span><span style="color:rgb(212,212,212)">]</span></div><div><span style="color:rgb(212,212,212)">    assertEquals(res, </span><span style="color:rgb(181,206,168)">3</span><span style="color:rgb(212,212,212)">)</span></div><div><span style="color:rgb(212,212,212)">  }</span></div><br><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><stdarg.h></span></div><div><span style="color:rgb(197,134,192)">#include</span><span style="color:rgb(86,156,214)"> </span><span style="color:rgb(206,145,120)"><stdio.h></span></div><br><div><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">add_var</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">n</span><span style="color:rgb(212,212,212)">, ...) {</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> Sum = </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">;</span></div><br><div><span style="color:rgb(212,212,212)">    va_list ptr;</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(220,220,170)">va_start</span><span style="color:rgb(212,212,212)">(ptr, n);</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(197,134,192)">for</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> i = </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)">; i < n; i++) { </span></div><div><span style="color:rgb(212,212,212)">        </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> i = </span><span style="color:rgb(220,220,170)">va_arg</span><span style="color:rgb(212,212,212)">(ptr, </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)">);</span></div><div><span style="color:rgb(212,212,212)">        </span><span style="color:rgb(220,220,170)">printf</span><span style="color:rgb(212,212,212)">(</span><span style="color:rgb(206,145,120)">"lala </span><span style="color:rgb(156,220,254)">%d</span><span style="color:rgb(206,145,120)">"</span><span style="color:rgb(212,212,212)">, i);</span></div><div><span style="color:rgb(212,212,212)">        Sum += </span><span style="color:rgb(220,220,170)">va_arg</span><span style="color:rgb(212,212,212)">(ptr, </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)">);</span></div><div><span style="color:rgb(212,212,212)">    }</span></div></div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(220,220,170)">va_end</span><span style="color:rgb(212,212,212)">(ptr);</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(197,134,192)">return</span><span style="color:rgb(212,212,212)"> Sum;</span></div>}<br><br><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">The output of the test code is consistent with my autogenerated code, </span></span></div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">the Ints are not reaching the add_var function in a proper state, and therefore </span></span></div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-weight:normal;font-size:12px;line-height:18px;white-space:pre-wrap"><span style="color:rgb(0,0,0)"><span style="background-color:rgb(255,255,255)">add_var is returning something like 840370212 instead of 3. <br></span></span></div></div></div></div>