[Bug c/89329] New: "-O2" optimization causes a infinite loop

2019-02-13 Thread jungmin.song at nuance dot com
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.

[Bug tree-optimization/89329] "-O2" optimization causes a infinite loop

2019-02-19 Thread jungmin.song at nuance dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89329

--- Comment #2 from Jungmin Song  ---
My understanding is that the compiler with O2 assumes that 'i' should be under
ARR_MAX becuase there was undifend behavior, if it was not.
Would you please point me to where is is in C standard? Becuase I'm not much
faiilar with that part, it would be very appreciated.