Bug 70741 - segfault when jumping into statement expression in array initializer
Summary: segfault when jumping into statement expression in array initializer
Status: RESOLVED DUPLICATE of bug 772
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.2.1
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-20 21:20 UTC by Donald Chai
Modified: 2021-07-22 21:57 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 Donald Chai 2016-04-20 21:20:34 UTC
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
Comment 1 Andrew Pinski 2021-07-22 21:57:52 UTC
the C++ statement expression issues for jumping into a statement expression is PR 772 (C front-end already rejects this).

*** This bug has been marked as a duplicate of bug 772 ***