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

            Bug ID: 120616
           Summary: Incorrect code with -O3 and compound literal
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fanghs666 at gmail dot com
  Target Milestone: ---

int printf(const char *format, ...);

struct S {
    int a;
    int b;
    int c;
};

int func(struct S *s, long *g, long *o) {
    if (*o < 1) {
        switch (s->a) {
            case 1: {
                if (s->b < s->c)
                    return 1;
                return 0;
            }
            case 2: {
                if (*g)
                    break;
            }
            default: {
                return 0;
                break;
            }
        }
    }
    return 1;
}

static short g_arr[6] = {};
int main() {
    long long l_arr[5] = {1, 2};
    long long k = l_arr[func((struct S[]){(struct S){}}, 0, (long *)(long
long[]){0, 0})];
    printf("=%lld\n", k);

    for (int i = 0; i < 6; i++)
        for (int j = 0; j < 10; j++)
        printf("", g_arr[i]);
}

The expected output is "=1".

$ gcc-trunk -O3 a.c
$ ./a.out
=2

Reply via email to