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:

00008000 <func>:
    8000:       4b02            ldr     r3, [pc, #8]    ; (800c <func+0xc>)
    8002:       681b            ldr     r3, [r3, #0]
    8004:       b903            cbnz    r3, 8008 <func+0x8>
    8006:       e7fe            b.n     8006 <func+0x6>
    8008:       4770            bx      lr
    800a:       bf00            nop
    800c:       00018010        andeq   r8, r1, r0, lsl r0

Disassembly of section .bss:

00018010 <ptr>:
   18010:       00000000        andeq   r0, r0, r0

Disassembly of section .comment:

00000000 <.comment>:
   0:   3a434347        bcc     10d0d24 <_stack+0x1050d24>
   4:   4e472820        cdpmi   8, 4, cr2, cr7, cr0, {1}
   8:   36202955                        ; <UNDEFINED> instruction: 0x36202955
   c:   302e332e        eorcc   r3, lr, lr, lsr #6
        ...

Disassembly of section .ARM.attributes:

00000000 <_stack-0x80000>:
   0:   00003241        andeq   r3, r0, r1, asr #4
   4:   61656100        cmnvs   r5, r0, lsl #2
   8:   01006962        tsteq   r0, r2, ror #18
   c:   00000028        andeq   r0, r0, r8, lsr #32
  10:   726f4305        rsbvc   r4, pc, #335544320      ; 0x14000000
  14:   2d786574        cfldr64cs       mvdx6, [r8, #-464]!     ; 0xfffffe30
  18:   0600344d        streq   r3, [r0], -sp, asr #8
  1c:   094d070d        stmdbeq sp, {r0, r2, r3, r8, r9, sl}^
  20:   14041202        strne   r1, [r4], #-514 ; 0xfffffdfe
  24:   17011501        strne   r1, [r1, -r1, lsl #10]
  28:   19011803        stmdbne r1, {r0, r1, fp, ip}
  2c:   1e011a01        vmlane.f32      s2, s2, s2
  30:   Address 0x0000000000000030 is out of bounds.

------------------------------------------------------------------------------

As you can see, the instruction at 8006 calls itself infinitely.

Reply via email to