<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54148>54148</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AVR] incorrect stack offset of char type arguments passed via stack
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          beenshi
      </td>
    </tr>
</table>

<pre>
    For the following C code
```
char add(char a, char b, ...) {
  return a + b;
}
```

avr-gcc generates
```
add:
        push r28
        push r29
        in r28,__SP_L__
        in r29,__SP_H__
/* prologue: function */
/* frame size = 0 */
/* stack size = 2 */
.L__stack_usage = 2
        ldd r24,Y+6
        ldd r25,Y+5
        add r24,r25
/* epilogue start */
        pop r29
        pop r28
        ret
```
The argument `a` is put on `Y+6` and `b` is put on `Y+5`.

But clang generates
```
add:                                    ; @add
; %bb.0:
        push    r28
        push    r29
        in      r28, 61
        in      r29, 62
        ldd     r24, Y+5
        ldd     r25, Y+7
        add     r25, r24
        mov     r24, r25
        lsl     r25
        sbc     r25, r25
        pop     r29
        pop     r28
        ret
```
The argument `a` is put on `Y+7` and `b` is put on `Y+5`.

A char type argument should only cost 1 byte when passing by stack frame.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVMGumzAQ_BpzsR4iJkA4cEheFPXQQ9VWlXqKbDDg1sHINonSr-_aQEKiHF6lohC8O-P1eHdtpqprcVAa25bjWkmpLqJr8DsuVcVRtEfRFqXR9PNm2VKNaVUhshmHiADbjZgbhWGISI5RthvpGGtuB91hihHZASeeAJTtX8Yf_-lZvzVliRvecU0tNy-5Tka8nefl_WBarMnm2ZHfHKLzOHk_Hr99OX4-Hh-RfEY-3RByQGSLe62kagYOq-F66EorVAf78fCSV2t64tiIPxyjeI-jVxxjafn7ziEPnBA0ecJxMLSZGDeRsqpA5RpU_oRkpk_-ZPInNz-98R26FMF74Tfk1Gj7KBPypvqHtI32Pa9Q0pf1-A5NRHUznHgHMdOIwouFwf1gsUtYGo26wUu7ytnsJSOBb7hshx3ApaTQmR9pCPyBB_oQo3XkJoyBnE0SxsLouaXchp-ayruWbTVx4ACkq2d37t0PVfR-Vxf8WLAZSmYoW9byDrnJM3BS53u4e50hmJHTjNljWLmMkSwL_LSl2fO_ip79e9G347Vir_1iAdOqQVYwTV7hjjIWrzC7Wo4vLe9wT41x1xe7TqfMn8cwqIq4yuOcBlZYyQuU7LY_vqJkj0VXKq15aSe-qmvDQVT9Ymnjw_MKnwUd6cGgZdFa2xvXMu5gHRph24GFpTqBIeV5_rzBDfIL1gFTGDNA-5JDsl6tN0FbZJtolearlKRVlsY8zWhNoppmZcaqpGI8kJRxaZxsREjHL9iHgDFsIRAFiQiJ4oisYhIneZjldZxGaRJXjKZ1RqHL-YkKGTododJNoAsviQ2NAVAKY80ddClsOu6z5OLTwbZKF4zzzrQi8EsXXvpfDKS0NQ">