https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89329

            Bug ID: 89329
           Summary: "-O2" optimization causes a infinite loop
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jungmin.song at nuance dot com
  Target Milestone: ---

Created attachment 45688
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45688&action=edit
Sample code generating this issue

With O2 optimization, an infinite loop is generated from the attached code.

    for (i = 0; i < pStruct->count1; ++i) {
        unsigned short pWord = pStruct->array2[i];
        CheckArray1_ext(pWord);
    }

    for (; i < ARR_MAX; ++i) {
        pStruct->array1[i] = i;
    }

The generated code with "arm-none-eabi-gcc.exe -S -O2 compileOptimizationErr.c
-o compileOptimizationErr.c.O2.s" checks only if it is equal with ARR_MAX for
the second loop. If the value of 'i' is over ARR_MAX before the second loop,
there is no condition to exit the loop.

Reply via email to