gcc-10 compilation failure in c_expr_sizeof_expr

Bug #1904630 reported by Colin Ian King
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Invalid
Medium
gcc-10 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

gcc version 10.2.0 (Ubuntu 10.2.0-17ubuntu1)

$ cat qq.c

int m(int a, int b) { return sizeof((char[a][b])); }

gcc qq.c
qq.c: In function ‘m’:
qq.c:1:49: error: expected expression before ‘)’ token
    1 | int m(int a, int b) { return sizeof((char[a][b])); }
      | ^
qq.c:1:49: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in c_expr_sizeof_expr, at c/c-typeck.c:2946
0x764982 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
 ../../src/gcc/tree.c:9780
0x5c561d tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
 ../../src/gcc/tree.h:3417
0x5c561d c_expr_sizeof_expr(unsigned int, c_expr)
 ../../src/gcc/c/c-typeck.c:2946
0xa2c748 c_parser_sizeof_expression
 ../../src/gcc/c/c-parser.c:8348
0xa2c748 c_parser_unary_expression
 ../../src/gcc/c/c-parser.c:8245
0xa2d38d c_parser_cast_expression
 ../../src/gcc/c/c-parser.c:8115
0xa2d619 c_parser_binary_expression
 ../../src/gcc/c/c-parser.c:7918
0xa2e5f5 c_parser_conditional_expression
 ../../src/gcc/c/c-parser.c:7652
0xa2ec10 c_parser_expr_no_commas
 ../../src/gcc/c/c-parser.c:7569
0xa2ee71 c_parser_expression
 ../../src/gcc/c/c-parser.c:10644
0xa2f617 c_parser_expression_conv
 ../../src/gcc/c/c-parser.c:10677
0xa25af1 c_parser_statement_after_labels
 ../../src/gcc/c/c-parser.c:6212
0xa26fa1 c_parser_compound_statement_nostart
 ../../src/gcc/c/c-parser.c:5805
0xa45a74 c_parser_compound_statement
 ../../src/gcc/c/c-parser.c:5617
0xa47531 c_parser_declaration_or_fndef
 ../../src/gcc/c/c-parser.c:2505
0xa4f6a3 c_parser_external_declaration
 ../../src/gcc/c/c-parser.c:1745
0xa501a9 c_parser_translation_unit
 ../../src/gcc/c/c-parser.c:1618
0xa501a9 c_parse_file()
 ../../src/gcc/c/c-parser.c:21752
0xaa81d3 c_common_parse_file()
 ../../src/gcc/c-family/c-opts.c:1190
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-10/README.Bugs> for instructions.

Revision history for this message
Colin Ian King (colin-king) wrote :

Note that the workaround is just to remove the extra ( ), e.g. int m(int a, int b) { return sizeof(char[a][b]); }

Revision history for this message
Colin Ian King (colin-king) wrote :

Fails in the same way with just: int m(int a) { return sizeof((char[a])); };

Revision history for this message
Colin Ian King (colin-king) wrote :

Regression; this does not crash the compiler with gcc-9.3.0

Revision history for this message
Matthias Klose (doko) wrote :

confirmed, but that's invalid code:

$ gcc-9 -c qq.i
qq.i: In function ‘m’:
qq.i:1:49: error: expected expression before ‘)’ token
    1 | int m(int a, int b) { return sizeof((char[a][b])); }
      | ^

Changed in gcc-10 (Ubuntu):
status: New → Confirmed
Revision history for this message
In , Matthias Klose (doko) wrote :

seen with the gcc-10 branch and the trunk, gcc configured with
--enable-checking=yes,extra,rtl

gcc-9 configured here with --enable-checking=release, so I don't know if that's a regression.

$ cat qq.i
int m(int a) { return sizeof((char[a])); };

$ gcc-9 -c qq.i
qq.i: In function ‘m’:
qq.i:1:39: error: expected expression before ‘)’ token
    1 | int m(int a) { return sizeof((char[a])); };
      | ^

$ gcc-10 -c qq.i
qq.i: In function ‘m’:
qq.i:1:39: error: expected expression before ‘)’ token
    1 | int m(int a) { return sizeof((char[a])); };
      | ^
qq.i:1:39: internal compiler error: tree check: expected class ‘type’, have ‘exceptional’ (error_mark) in c_expr_sizeof_expr, at c/c-typeck.c:2946
0x7602ef tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*)
        ../../src/gcc/tree.c:9780
0x5c2697 tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
        ../../src/gcc/tree.h:3417
0x5c2697 c_expr_sizeof_expr(unsigned int, c_expr)
        ../../src/gcc/c/c-typeck.c:2946
0xa274b7 c_parser_sizeof_expression
        ../../src/gcc/c/c-parser.c:8348
0xa274b7 c_parser_unary_expression
        ../../src/gcc/c/c-parser.c:8245
0xa280fd c_parser_cast_expression
        ../../src/gcc/c/c-parser.c:8115
0xa28389 c_parser_binary_expression
        ../../src/gcc/c/c-parser.c:7918
0xa29365 c_parser_conditional_expression
        ../../src/gcc/c/c-parser.c:7652
0xa29980 c_parser_expr_no_commas
        ../../src/gcc/c/c-parser.c:7569
0xa29be1 c_parser_expression
        ../../src/gcc/c/c-parser.c:10644
0xa2a387 c_parser_expression_conv
        ../../src/gcc/c/c-parser.c:10677
0xa20861 c_parser_statement_after_labels
        ../../src/gcc/c/c-parser.c:6212
0xa21d11 c_parser_compound_statement_nostart
        ../../src/gcc/c/c-parser.c:5805
0xa407c4 c_parser_compound_statement
        ../../src/gcc/c/c-parser.c:5617
0xa42281 c_parser_declaration_or_fndef
        ../../src/gcc/c/c-parser.c:2505
0xa4a3f3 c_parser_external_declaration
        ../../src/gcc/c/c-parser.c:1745
0xa4aef1 c_parser_translation_unit
        ../../src/gcc/c/c-parser.c:1618
0xa4aef1 c_parse_file()
        ../../src/gcc/c/c-parser.c:21752
0xaa21fb c_common_parse_file()
        ../../src/gcc/c-family/c-opts.c:1190
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.

affects: groovy → gcc
Revision history for this message
In , Marxin-m (marxin-m) wrote :

It's at least as old as GCC 4.8.0.

Changed in gcc:
importance: Unknown → Medium
status: Unknown → Confirmed
Revision history for this message
In , Rguenth (rguenth) wrote :

GCC 10.3 is being released, retargeting bugs to GCC 10.4.

Revision history for this message
In , Pinskia (pinskia) wrote :

Dup of bug 101171.

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

Changed in gcc:
status: Confirmed → Invalid
Revision history for this message
Matthias Klose (doko) wrote :

fixed in 10.5.0

Changed in gcc-10 (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Colin Ian King (colin-king) wrote :

Thanks doko!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.