[AVR] dynamic stack array is not implemented
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
For the following C code,
```c++
char ass(int a, int b) {
char arr[a];
return arr[b];
}
```
`clang a.c -O0 -S --target=avr -mmcu=atmega328` emits empty function body as
```asm
.file "a.c"
.text
.globl ass ; -- Begin function ass
.p2align 1
.type ass,@function
ass: ; @ass
; %bb.0: ; %entry
ret
.Lfunc_end0:
.size ass, .Lfunc_end0-ass
; -- End function
```
while `avr-gcc-7.3` emits
```asm
.text
.global ass
.type ass, @function
ass:
push r28
push r29
in r28,__SP_L__
in r29,__SP_H__
/* prologue: function */
/* frame size = 0 */
/* stack size = 2 */
.L__stack_usage = 2
in r18,__SP_L__
in r19,__SP_H__
lsl r24
rol r25
in r20,__SP_L__
in r21,__SP_H__
sub r20,r24
sbc r21,r25
in __tmp_reg__,__SREG__
cli
out __SP_H__,r21
out __SREG__,__tmp_reg__
out __SP_L__,r20
in r30,__SP_L__
in r31,__SP_H__
adiw r30,1
lsl r22
rol r23
add r30,r22
adc r31,r23
sbiw r30,2
ld r24,Z
ldd r25,Z+1
in __tmp_reg__,__SREG__
cli
out __SP_H__,r19
out __SREG__,__tmp_reg__
out __SP_L__,r18
/* epilogue start */
pop r29
pop r28
ret
```
Contributor guide
Research direction
Start by reproducing the issue with the shown C++ source and clang command targeting AVR at -O0, then compare the generated assembly with the avr-gcc output. Trace the AVR compiler path responsible for dynamic stack allocation and array access; done means the function emits correct assembly instead of an empty body.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100