https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70223
Bug ID: 70223 Summary: [ARM] Optimization level -O2 results in wrong code Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: satishbmsce at gmail dot com Target Milestone: --- -fschedule-insns2 flag within optimization level -O2 results in wrong code. By adding one more argument to test function 'doStreamReadBlock' defined in file 'gcc/testsuite/gcc.target/arm/stack-red-zone.c' issue can produced. /x86_64-unknown-linux-gnu/bin/gcc -B /x86_64-unknown-linux-gnu/bin -msoft-float -marm -mcpu=cortex-a9 -march=armv7-a -mno-thumb-interwork -mlong-calls -mno-unaligned-access -O2 test.c test.c: extern int doStreamReadBlock (int *, char *, int size, int, int); char readStream (int *s) { char c = 0; doStreamReadBlock (s, &c, 1, *s, 22); return c; } 00000000 <readStream>: 0: e1a0c00d mov ip, sp 4: e3a02000 mov r2, #0 8: e92dd800 push {fp, ip, lr, pc} c: e24cb004 sub fp, ip, #4 10: e24dd008 sub sp, sp, #8 14: e24b100c sub r1, fp, #12 18: e3a0c016 mov ip, #22 1c: e5612001 strb r2, [r1, #-1]! 20: e3a02001 mov r2, #1 24: e5903000 ldr r3, [r0] 28: e58dc000 str ip, [sp] 2c: e59fc00c ldr ip, [pc, #12] ; 40 <readStream+0x40> 30: e12fff3c blx ip 34: e24bd00c sub sp, fp, #12 <---- Stack frame de-allocated 38: e55b000d ldrb r0, [fp, #-13] <---- Accessing stack. 3c: e89da800 ldm sp, {fp, sp, pc} 40: 00000000 andeq r0, r0, r0