Bug 27008 - Simple nested for loop generates bad code on mac in O2, O3
Summary: Simple nested for loop generates bad code on mac in O2, O3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-03 18:57 UTC by John Elliott
Modified: 2006-04-04 05:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Elliott 2006-04-03 18:57:35 UTC
gcc version 3.3, Apple build 1495, ppc-darwin.

command-line: gcc -O3 file.c
output: 1 2 0 0 5 6 0 0 9 10 0 0 13 14 0 0 17 18

command-line: gcc -O0 file.c
output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Compile and run the following file with optimization < O2. The output is a list of integers from 1--18. When compiled with >= O2, the list contains "holes" (the integers 3,4,7,8,11,12,15,16 display as 0).

#include <stdlib.h>
#include <stdio.h>

static void f(int in1, int *out11);
static void init(int in1, int *out1, int *out2, int *out11, int *out21);
static void dump(int *out11);

int
main()
{
    int out11[18] = { 0 };
    int in1 = 0;
    f(in1,out11);

    return 0;
}
static void f(int in1, int *out11)
{
    int b_out21 = 0;
    int b_out11[18] = { 0 };
    int b_out5 = 0;
    int b_out2 = 0;
    int b_out1 = 0;

    init(in1, &b_out1, &b_out2, (int *)b_out11, &b_out21);
    for(b_out2 = 0; b_out2 < 9; b_out2++) {
        for(b_out5 = 0; b_out5 < 2; b_out5++) {
            out11[b_out5 + (b_out2 << 1)] = b_out11[b_out5 + (b_out2 << 1)];
        }
    }
    dump(out11);
}
static void init(int in1, int *out1, int *out2, int *out11, int *out21)
{
    int i;

    for(i = 0; i < 18; ++i) {
        out11[i] = i+1;
    }
}
static void dump(int *out11)
{
    int i;

    for(i = 0; i < 18; ++i) {
        printf("%d ", out11[i]);
    }
    printf("\n");
}
Comment 1 Andrew Pinski 2006-04-03 19:02:20 UTC
Report this bug to Apple since this is Apple's GCC that has been heavly modified.
Comment 2 Andrew Pinski 2006-04-04 05:22:26 UTC
Fixed in 4.0.0 and above already so closing as fixed as 3.4.6 was the last release of 3.4.6 but I doubt this was ever reproducible with FSF's GCC.