Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 788829 - >=sys-devel/gcc-10.3: internal compiler error when using designated initializers in C++ code
Summary: >=sys-devel/gcc-10.3: internal compiler error when using designated initializ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://gcc.gnu.org/PR100489
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-07 20:59 UTC by Martin Kolleck
Modified: 2021-06-10 07:52 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Kolleck 2021-05-07 20:59:02 UTC
The following code causes an internal compiler error in gcc-10.3 and gcc-11.1.

union U
{
  struct
  {
    unsigned char a;
  };

  unsigned char b[1];
};

void f(unsigned char a)
{
  union U u = { .a = a };
}

Reproducible: Always

Steps to Reproduce:
1. Store example code as ice.cpp
2. Compiling with current stable g++ works.
   g++-10.2.0 -c -o /dev/null ice.cpp
3. Compiling with unstable g++-10.3 or g++11.1 results in internal compiler error.
   g++-11.1.0 -c -o /dev/null ice.cpp

Actual Results:  
ice.cpp: In function ‘void f(unsigned char)’:
ice.cpp:13:30: internal compiler error: in get_or_insert_ctor_field, at cp/constexpr.c:3556
   13 |         union U u = { .a = a };
      |                              ^
0x1092ad1 internal_error(char const*, ...)
        ???:0
0x1092bb8 fancy_abort(char const*, int, char const*)
        ???:0
0x1103f73 maybe_constant_value(tree_node*, tree_node*, bool)
        ???:0
0x110a1b2 cp_fully_fold_init(tree_node*)
        ???:0
0x1194cbb store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ???:0
0x111b691 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        ???:0
0x1561092 c_parse_file()
        ???:0
0x158e414 c_common_parse_file()
        ???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.


Expected Results:  
Compilation succeeds.

This is probably a bug in GCC itself, but the output said to file the bug here.

With different compiler options, there are more interesting results:

Adding '-ansi` to the command line lets the compilation succeed.

Adding '-ansi -pedantic' to the command line lets the compilation succeed and produces the following warnings:

ice.cpp:4:9: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
    4 |         {
      |         ^
ice.cpp: In function ‘void f(unsigned char)’:
ice.cpp:13:23: warning: C++ designated initializers only available with ‘-std=c++20’ or ‘-std=gnu++20’ [-Wpedantic]
   13 |         union U u = { .a = a };
      |                       ^

Adding '-ansi -pedantic -std=gnu++20' to the command line causes the ICE, again.
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2021-05-08 21:23:00 UTC
Nice test case!

Happens on gcc master as well:

$ LANG=C h g++ -c -o /dev/null ice.cpp
ice.cpp: In function 'void f(unsigned char)':
ice.cpp:14:24: internal compiler error: in get_or_insert_ctor_field, at cp/constexpr.c:3556
   14 |   union U u = { .a = a };
      |                        ^
0x5fed0e get_or_insert_ctor_field
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:3556
0x68f2a2 cxx_eval_bare_aggregate
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:4455
0x685466 cxx_eval_constant_expression
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:6675
0x688030 cxx_eval_outermost_constant_expr
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:7251
0x68b592 maybe_constant_value(tree_node*, tree_node*, bool)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/constexpr.c:7525
0x6ab92c cp_fully_fold(tree_node*)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2146
0x6ab92c cp_fully_fold(tree_node*)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2138
0x6ab9d4 cp_fully_fold_init(tree_node*)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/cp-gimplify.c:2167
0x82219a store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/typeck2.c:816
0x6bd08d check_initializer
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/decl.c:7080
0x6d6a8f cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/decl.c:8014
0x796139 cp_parser_init_declarator
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:21891
0x7730ae cp_parser_simple_declaration
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:14457
0x77509d cp_parser_declaration_statement
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:13592
0x7756ab cp_parser_statement
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:11822
0x776eae cp_parser_statement_seq_opt
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:12189
0x776f70 cp_parser_compound_statement
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:12138
0x794117 cp_parser_function_body
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:24080
0x794117 cp_parser_ctor_initializer_opt_and_function_body
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:24131
0x79541a cp_parser_function_definition_after_declarator
        /tmp/portage-tmpdir/portage/sys-devel/gcc-12.0.0_pre9999/work/gcc-12.0.0_pre9999/gcc/cp/parser.c:30068
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2021-05-08 21:42:13 UTC
Filed upstream bug report as https://gcc.gnu.org/PR100489
Comment 3 Larry the Git Cow gentoo-dev 2021-05-20 22:14:29 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=d9ec8d21d27b98b1ae8a0fe33c8917868a14ba63

commit d9ec8d21d27b98b1ae8a0fe33c8917868a14ba63
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-05-20 22:14:05 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-05-20 22:14:05 +0000

    11.1.0: backport PR100489: union constructor fix
    
    Reported-by: Martin Kolleck
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 11.1.0/gentoo/28_all_ctor-union-PR100489.patch | 156 +++++++++++++++++++++++++
 11.1.0/gentoo/README.history                   |   1 +
 2 files changed, 157 insertions(+)

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=1b262115460489ec8736bfa5102c62656d580fb5

commit 1b262115460489ec8736bfa5102c62656d580fb5
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-05-20 22:12:59 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-05-20 22:12:59 +0000

    10.3.0: backport PR100489: union constructor fix
    
    Reported-by: Martin Kolleck
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 10.3.0/gentoo/33_all_ctor-union-PR100489.patch | 71 ++++++++++++++++++++++++++
 10.3.0/gentoo/README.history                   |  3 ++
 2 files changed, 74 insertions(+)
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2021-05-20 22:16:20 UTC
It will take a while to release next gcc patchset in Gentoo (a few weeks).

Until them you can try a patch
    https://gitweb.gentoo.org/proj/gcc-patches.git/plain/11.1.0/gentoo/28_all_ctor-union-PR100489.patch
by dropping it to /etc/portage/patches/sys-devel/gcc:11/ and check if it works for you.
Comment 5 Martin Kolleck 2021-05-26 08:53:04 UTC
Thanks. The patch does work for me.
Comment 6 Larry the Git Cow gentoo-dev 2021-06-10 07:36:13 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=9d40799e2ef69d8650dd59325c0e84b902258b00

commit 9d40799e2ef69d8650dd59325c0e84b902258b00
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-06-10 07:28:54 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-06-10 07:28:54 +0000

    11.1.0: cut 2 patchset
    
    Five new patches:
    + 27_all_msp430-f2c.patch: fix build on 16-bit targets
    + 28_all_ctor-union-PR100489.patch: fix ICE on some c++ initializers
    + 29_all_perfect-implicit-PR100644.patch: fix move deletion (fireofx build)
    + 30_all_arm-lto-ICE-march-mix.patch: fix LTO ICE on arm -march=/-mtune mix
    + 31_all_ICE-tsubst-PR100102.patch:
    
    Bug: https://gcc.gnu.org/PR100361
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Bug: https://gcc.gnu.org/PR100644
    Bug: https://bugs.gentoo.org/792705
    Bug: https://gcc.gnu.org/PR100767
    Bug: https://bugs.gentoo.org/792291
    Bug: https://bugs.gentoo.org/794775
    Bug: https://gcc.gnu.org/PR100102
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 11.1.0/gentoo/README.history | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 7 Larry the Git Cow gentoo-dev 2021-06-10 07:45:29 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=4fdc5533816df36a81b6c57dcf7c2233a87f2d46

commit 4fdc5533816df36a81b6c57dcf7c2233a87f2d46
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-06-10 07:40:21 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-06-10 07:40:21 +0000

    10.3.0: cut 2 patchset
    
    Five new patches:
    + 33_all_ctor-union-PR100489.patch: fix ICE on some c++ initializers
    + 34_all_ICE-tsubst-PR100102.patch: fix ICE in c++ tempate substitution
    
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Bug: https://bugs.gentoo.org/794775
    Bug: https://gcc.gnu.org/PR100102
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 10.3.0/gentoo/README.history | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 8 Larry the Git Cow gentoo-dev 2021-06-10 07:50:34 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=187f062a6f1a768d0e33e0f10c63feb2e74d0b49

commit 187f062a6f1a768d0e33e0f10c63feb2e74d0b49
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-06-10 07:49:15 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-06-10 07:50:32 +0000

    sys-devel/gcc: 10.3.0: cut 2 patchset
    
    Two new patches:
    + 33_all_ctor-union-PR100489.patch: fix ICE on some c++ initializers
    + 34_all_ICE-tsubst-PR100102.patch: fix ICE in c++ tempate substitution
    
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Bug: https://bugs.gentoo.org/794775
    Bug: https://gcc.gnu.org/PR100102
    Package-Manager: Portage-3.0.19, Repoman-3.0.3
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 sys-devel/gcc/Manifest             |  1 +
 sys-devel/gcc/gcc-10.3.0-r1.ebuild | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b250f4243abd49acdd459751ae1e55c995bf9818

commit b250f4243abd49acdd459751ae1e55c995bf9818
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-06-10 07:39:30 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-06-10 07:50:31 +0000

    sys-devel/gcc: 11.1.0: cut 2 patchset
    
    Five new patches:
    + 27_all_msp430-f2c.patch: fix build on 16-bit targets
    + 28_all_ctor-union-PR100489.patch: fix ICE on some c++ initializers
    + 29_all_perfect-implicit-PR100644.patch: fix move deletion (fireofx build)
    + 30_all_arm-lto-ICE-march-mix.patch: fix LTO ICE on arm -march=/-mtune mix
    + 31_all_ICE-tsubst-PR100102.patch: fix ICE in c++ tempate substitution
    
    Bug: https://gcc.gnu.org/PR100361
    Bug: https://bugs.gentoo.org/788829
    Bug: https://gcc.gnu.org/PR100489
    Bug: https://gcc.gnu.org/PR100644
    Bug: https://bugs.gentoo.org/792705
    Bug: https://gcc.gnu.org/PR100767
    Bug: https://bugs.gentoo.org/792291
    Bug: https://bugs.gentoo.org/794775
    Bug: https://gcc.gnu.org/PR100102
    Package-Manager: Portage-3.0.19, Repoman-3.0.3
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 sys-devel/gcc/Manifest             |  1 +
 sys-devel/gcc/gcc-11.1.0-r1.ebuild | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2021-06-10 07:52:59 UTC
Should be fixed in gcc-11.1.0-r1 and gcc-10.3.0-r1.