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

            Bug ID: 70741
           Summary: segfault when jumping into statement expression in
                    array initializer
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: donald.chai at synopsys dot com
  Target Milestone: ---

Preface:
1) Apologies if this is the wrong component.
2) Yes, this code is crazy.  I was testing our own compiler.  :)

GCC 5.x segfaults on the below code in C++ mode.

$ cat test.c
void testE_statement() {
    int x[10] = {
        ({ L: 0; })
    };
    goto L;
}

$ gcc-5 -c test.c       
test.c: In function ‘testE_statement’:
test.c:5:5: error: jump into statement expression
     goto L;
     ^
test.c:3:12: note: label ‘L’ defined here
         ({ L: 0; })

$ gcc-5 -c -x c++ test.c      
test.c: In function ‘void testE_statement()’:
test.c:1:6: internal compiler error: Segmentation fault
 void testE_statement() {
      ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.

$ gcc-5 --version
gcc-5 (Ubuntu 5.2.1-23ubuntu1~12.04) 5.2.1 20151031
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GCC 4.9 appears to do something somewhat reasonable:

$ cat test.cpp 
#include <cstdio>

int main() {
    int iters = 0;
    int x[10] = {
        ({ printf("0\n"); iters; }),
        ({ L: iters++; printf("1\n"); iters; })
    };
    if (iters < 2)
        goto L;
    printf("x[0]: %d\n", x[0]);
    printf("x[1]: %d\n", x[1]);
}
$ gcc-4.9 test.cpp
$ ./a.out 
0
1
1
x[0]: 0
x[1]: 2

Reply via email to