https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79023
Bug ID: 79023
Summary: ARM: Compiler optimizations cause branch instruction
within while loop to call itself infinitely.
Product: gcc
Version: 6.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: geo...@george-morgan.com
Target Milestone: ---
The code compiled with "arm-none-eabi-gcc -nostartfiles -ffreestanding -Os
bug.c -o bug.o"
-
volatile void *ptr;
void func(void) {
while (!ptr);
}
-
Produces the following assembly output:
---
bug.o: file format elf32-littlearm
Disassembly of section .text:
8000 :
8000: 4b02ldr r3, [pc, #8]; (800c )
8002: 681bldr r3, [r3, #0]
8004: b903cbnzr3, 8008
8006: e7feb.n 8006
8008: 4770bx lr
800a: bf00nop
800c: 00018010andeq r8, r1, r0, lsl r0
Disassembly of section .bss:
00018010 :
18010: andeq r0, r0, r0
Disassembly of section .comment:
<.comment>:
0: 3a434347bcc 10d0d24 <_stack+0x1050d24>
4: 4e472820cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 36202955; instruction: 0x36202955
c: 302e332eeorcc r3, lr, lr, lsr #6
...
Disassembly of section .ARM.attributes:
<_stack-0x8>:
0: 3241andeq r3, r0, r1, asr #4
4: 61656100cmnvs r5, r0, lsl #2
8: 01006962tsteq r0, r2, ror #18
c: 0028andeq r0, r0, r8, lsr #32
10: 726f4305rsbvc r4, pc, #335544320 ; 0x1400
14: 2d786574cfldr64cs mvdx6, [r8, #-464]! ; 0xfe30
18: 0600344dstreq r3, [r0], -sp, asr #8
1c: 094d070dstmdbeq sp, {r0, r2, r3, r8, r9, sl}^
20: 14041202strne r1, [r4], #-514 ; 0xfdfe
24: 17011501strne r1, [r1, -r1, lsl #10]
28: 19011803stmdbne r1, {r0, r1, fp, ip}
2c: 1e011a01vmlane.f32 s2, s2, s2
30: Address 0x0030 is out of bounds.
--
As you can see, the instruction at 8006 calls itself infinitely.