Bug 93753 - [8 Regression] ICE on a flexible array followed by a member in an anonymous struct with an initializer
Summary: [8 Regression] ICE on a flexible array followed by a member in an anonymous s...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 9.3
Assignee: Martin Sebor
URL:
Keywords: accepts-invalid, ice-on-invalid-code, patch
Depends on:
Blocks: flexmembers
  Show dependency treegraph
 
Reported: 2020-02-15 04:46 UTC by Yongheng Chen
Modified: 2021-08-27 18:44 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.0, 5.5.0
Known to fail: 6.4.0, 7.5.0, 8.3.0
Last reconfirmed: 2020-02-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yongheng Chen 2020-02-15 04:46:30 UTC
POC:
---
struct {
    int mem [ ] ;
    int b ;
} s = {1};
---

run script:
---
g++ -o poc poc.cpp
---

g++ version:
---
g++ (GCC) 10.0.1 20200214 (experimental)
---

Stack dump:
---
poc.cpp:4:10: internal compiler error: in output_constructor_regular_field, at varasm.c:5255
    4 | } s = {1};
      |          ^
0x836f9b output_constructor_regular_field
        ../../gcc/varasm.c:5255
0x836f9b output_constructor
        ../../gcc/varasm.c:5536
0x1311bcd output_constant
        ../../gcc/varasm.c:4908
0x1311bcd assemble_variable_contents
        ../../gcc/varasm.c:2148
0x1317158 assemble_variable(tree_node*, int, int, int)
        ../../gcc/varasm.c:2327
0x131a9d9 varpool_node::assemble_decl()
        ../../gcc/varpool.c:587
0xbe50cc output_in_order
        ../../gcc/cgraphunit.c:2564
0xbe50cc symbol_table::compile()
        ../../gcc/cgraphunit.c:2801
0xbe733c symbol_table::compile()
        ../../gcc/cgraphunit.c:2717
0xbe733c symbol_table::finalize_compilation_unit()
        ../../gcc/cgraphunit.c:2984
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
---
Comment 1 Andrew Pinski 2020-02-16 02:03:02 UTC
This is invalid code.  The variable length field should be detected as not last field in the struct.
Comment 2 Martin Liška 2020-02-17 12:27:37 UTC
Started with r6-5791-g7e9a3ad30076ad8a. Before the revision we accepted the code.
Comment 3 Martin Sebor 2020-02-17 17:46:38 UTC
GCC rejects the code when the struct has a name:

$ cat t.C && gcc -S -Wall -Wextra t.C
struct S {
    int mem [ ] ;
    int b ;
} s = {1};
t.C:2:9: error: flexible array member ‘S::mem’ not at end of ‘struct S’
    2 |     int mem [ ] ;
      |         ^~~
t.C:4:9: warning: missing initializer for member ‘S::b’ [-Wmissing-field-initializers]
    4 | } s = {1};
      |         ^
Comment 4 Martin Sebor 2020-02-17 23:09:53 UTC
Patch: https://gcc.gnu.org/ml/gcc-patches/2020-02/msg00995.html
Comment 5 GCC Commits 2020-02-21 17:47:29 UTC
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:dbfba41e95d1d93b17e907b7f516b52ed3a3c415

commit r10-6789-gdbfba41e95d1d93b17e907b7f516b52ed3a3c415
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Feb 21 10:45:56 2020 -0700

    PR c++/93753 - ICE on a flexible array followed by a member in an anonymous struct with an initializer
    
    gcc/cp/ChangeLog:
    
    	PR gcov-profile/93753
    	* class.c (check_flexarrays): Tighten up a test for potential members
    	of anonymous structs or unions.
    
    gcc/testsuite/ChangeLog:
    
    	PR gcov-profile/93753
    	* g++.dg/ext/flexary36.C: New test.
    	* g++.dg/lto/pr93166_0.C: Make struct with flexarray valid.
Comment 6 Martin Sebor 2020-02-21 17:49:32 UTC
Fixed in GCC 10.0.  The fix should be backported.
Comment 7 GCC Commits 2020-03-05 16:41:03 UTC
The releases/gcc-9 branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:9ca4280a921b0094c7ef131c5c8a63b451ab9a05

commit r9-8342-g9ca4280a921b0094c7ef131c5c8a63b451ab9a05
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Mar 5 09:37:25 2020 -0700

    Backport fix for PR c++/93753 from trunk.
    
    gcc/cp/ChangeLog:
    	Backport from trunk.
    	2020-02-21  Martin Sebor  <msebor@redhat.com>
    
    	PR c++/93753
    	* class.c (check_flexarrays): Tighten up a test for potential members
    	of anonymous structs or unions.
    
    gcc/testsuite/ChangeLog:
    
    	Backport from trunk.
    	2020-02-21  Martin Sebor  <msebor@redhat.com>
    
    	PR c++/93753
    	* g++.dg/ext/flexary36.C: New test.
Comment 8 Jakub Jelinek 2021-05-14 13:23:12 UTC
The GCC 8 branch is being closed, fixed in GCC 9.3.