Poor code for alloca

Bug #638687 reported by Yao Qi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro GCC
Invalid
Undecided
Unassigned

Bug Description

#include <alloca.h>
extern void bar(void *);

int foo(int i)
{
  bar(alloca(i));
  return 0;
}
$ arm-none-linux-gnueabi-gcc --version
arm-none-linux-gnueabi-gcc (GCC) 4.6.0 20100907 (experimental)
$arm-none-linux-gnueabi-gcc -march=armv7-a -O2 -S poor_alloca.c

FSF GCC trunk generate codes:

foo:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, uses_anonymous_args = 0
        add r0, r0, #14
        bic r0, r0, #7
        stmfd sp!, {fp, lr}
        add fp, sp, #4
        sub sp, sp, r0
        mov r0, sp
        bl bar
        mov r0, #0
        sub sp, fp, #4
        ldmfd sp!, {fp, pc}

The instructions for alignment are not necessary.

[CodeSourcery #1675]

Tags: size task
Revision history for this message
Yao Qi (yao-codesourcery) wrote :

Code size will be reduced once this bug is fixed.

Revision history for this message
Yao Qi (yao-codesourcery) wrote :

Please ignore my comment #1, and sentence "The instructions for alignment are not necessary." in bug report.

After talk with cltang, we realize that alignment is necessary here. However, 'add r0, r0, #14' can be changed to 'add r0, r0, #7'.

Michael Hope (michaelh1)
tags: added: size task
Viktor (vchong)
Changed in gcc-linaro:
status: New → Confirmed
Changed in gcc-linaro:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.