/* The result should be 7. When compiled with gcc version 4.1.0 20050815 (experimental) with some patches from PLD (incl. PR7776, PR20297, PR23128, PR22533, PR23386) with -O, the result is 0. */ #include <stdio.h> int arr[100]; int *alloc(void) {return arr;} void fill(int n) { int *result = alloc(); int *dest = result; for(;;) { int *next; dest[0] = 7; if (--n == 0) break; next = dest + 1; dest = next; } } int main(void) { fill(5); printf("%d\n", arr[1]); return 0; } /* Looking at the generated assembly code, the whole loop is optimized out, except for filling the first element. Using less temporaries or inlining alloc() makes the bug disappear. The bug manifests only with optimization turned on. */
Confirmed, between t41.copyrename2 and t42.dom2, the V_MAY_DEF is removed. After *next_8 = 7; Before: # TMT.51_18 = V_MAY_DEF <TMT.51_4>; *dest_2 = 7; I think we are forgetting to copy the alias info. I think this is fixed by the patch for PR 23509: http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01647.html The tree-cfg.c part that is.
> I think this is fixed by the patch for PR 23509: > http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01647.html Indeed, applying this patch and recompiling gcc fixed the bug. Thanks.
(In reply to comment #2) > Indeed, applying this patch and recompiling gcc fixed the bug. Thanks. Thanks for trying the patch. I only thought about this patch because of the symptom was about the same as other bug was.
*** This bug has been marked as a duplicate of 23509 ***