Bug 107682 - [13/14 Regression] ICE in c_parser_braced_init, at c/c-parser.cc:5619
Summary: [13/14 Regression] ICE in c_parser_braced_init, at c/c-parser.cc:5619
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 13.0
: P4 normal
Target Milestone: 13.2
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2022-11-14 17:30 UTC by G. Steinmetz
Modified: 2023-04-27 09:42 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-11-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2022-11-14 17:30:51 UTC
Started between 20220821 and 20220828 :
(gcc configured with --enable-checking=yes)


$ cat z1.c
int x() = {};

$ cat z2.c
int x(n) = {};


$ gcc-13-20221106 -c z1.c
z1.c:1:1: error: function 'x' is initialized like a variable
    1 | int x() = {};
      | ^~~
z1.c:1:1: internal compiler error: in fold_convert_loc, at fold-const.cc:2618
0xb06210 fold_convert_loc(unsigned int, tree_node*, tree_node*)
        ../../gcc/fold-const.cc:2618
0x80074c pop_init_level(unsigned int, int, obstack*, unsigned int)
        ../../gcc/c/c-typeck.cc:9100
0x8353e0 c_parser_braced_init
        ../../gcc/c/c-parser.cc:5619
0x8366b1 c_parser_initializer
        ../../gcc/c/c-parser.cc:5521
0x851387 c_parser_declaration_or_fndef
        ../../gcc/c/c-parser.cc:2436
0x85cf8f c_parser_external_declaration
        ../../gcc/c/c-parser.cc:1833
0x85d8bd c_parser_translation_unit
        ../../gcc/c/c-parser.cc:1695
0x85d8bd c_parse_file()
        ../../gcc/c/c-parser.cc:24359
0x8da031 c_common_parse_file()
        ../../gcc/c-family/c-opts.cc:1244
Comment 1 Marek Polacek 2022-11-14 17:35:50 UTC
Started with

commit 14cfa01755a66afbae2539f8b5796c960ddcecc6
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Thu Aug 25 21:02:57 2022 +0000

    c: Support C2x empty initializer braces
Comment 2 Marek Polacek 2022-11-14 17:37:57 UTC
I suppose pop_init_level needs to check that constructor_type isn't FUNCTION_TYPE.
Comment 3 Jakub Jelinek 2023-04-13 10:29:57 UTC
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109412#c3 should fix this too.
Comment 4 Richard Biener 2023-04-26 06:57:02 UTC
GCC 13.1 is being released, retargeting bugs to GCC 13.2.
Comment 5 GCC Commits 2023-04-27 09:36:28 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r14-287-ga1030fbf70eef5b635e4fbb904ec7209ebd137ca
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 27 11:35:55 2023 +0200

    c: Fix up error-recovery on functions initialized as variables [PR109412]
    
    The change to allow empty initializers in C broke error-recovery on the
    following testcase.  We are emitting function %qD is initialized like a
    variable error early; if the initializer is non-empty, we just emit
    another error that the initializer is invalid.  Previously if it was empty,
    we'd emit another error that scalar is being initialized by empty
    initializer (not really correct), but now we instead just try to
    build_zero_cst for the FUNCTION_TYPE and ICE on it.
    
    The following patch just emits the same diagnostics for the empty
    initializers as we emit for the non-empty ones.
    
    2023-04-27  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/107682
            PR c/109412
            * c-typeck.cc (pop_init_level): If constructor_type is FUNCTION_TYPE,
            reject empty initializer as invalid.
    
            * gcc.dg/pr109412.c: New test.
Comment 6 GCC Commits 2023-04-27 09:41:58 UTC
The releases/gcc-13 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:7e312adcb70ca7d67f0c2cf238cddec9b3243ff9

commit r13-7257-g7e312adcb70ca7d67f0c2cf238cddec9b3243ff9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Apr 27 11:35:55 2023 +0200

    c: Fix up error-recovery on functions initialized as variables [PR109412]
    
    The change to allow empty initializers in C broke error-recovery on the
    following testcase.  We are emitting function %qD is initialized like a
    variable error early; if the initializer is non-empty, we just emit
    another error that the initializer is invalid.  Previously if it was empty,
    we'd emit another error that scalar is being initialized by empty
    initializer (not really correct), but now we instead just try to
    build_zero_cst for the FUNCTION_TYPE and ICE on it.
    
    The following patch just emits the same diagnostics for the empty
    initializers as we emit for the non-empty ones.
    
    2023-04-27  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/107682
            PR c/109412
            * c-typeck.cc (pop_init_level): If constructor_type is FUNCTION_TYPE,
            reject empty initializer as invalid.
    
            * gcc.dg/pr109412.c: New test.
    
    (cherry picked from commit a1030fbf70eef5b635e4fbb904ec7209ebd137ca)
Comment 7 Jakub Jelinek 2023-04-27 09:42:50 UTC
Fixed for 13.2+ and 14+.