Bug 79657 - ICE on invalid c++ code in finish_underlying_type cp/semantics.c:3849
Summary: ICE on invalid c++ code in finish_underlying_type cp/semantics.c:3849
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2017-02-21 08:44 UTC by Martin Liška
Modified: 2017-02-22 19:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-02-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2017-02-21 08:44:22 UTC
Adopted from clang:

$ g++ /home/marxin/BIG/Programming/llvm-project/llvm/tools/clang/test/SemaCXX/underlying_type.cp

...

/home/marxin/BIG/Programming/llvm-project/llvm/tools/clang/test/SemaCXX/underlying_type.cpp:53:29: internal compiler error: Segmentation fault
     a = (__underlying_type(E)){}
                             ^
0x11cc42a crash_signal
	../../gcc/toplev.c:337
0x80d55e tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
	../../gcc/tree.h:3186
0xa5a5aa finish_underlying_type(tree_node*)
	../../gcc/cp/semantics.c:3849
0x996185 cp_parser_trait_expr
	../../gcc/cp/parser.c:9747
0x9a36d6 cp_parser_simple_type_specifier
	../../gcc/cp/parser.c:16753
0x9a304b cp_parser_type_specifier
	../../gcc/cp/parser.c:16519
0x9aba9b cp_parser_type_specifier_seq
	../../gcc/cp/parser.c:20804
0x9ab5cd cp_parser_type_id_1
	../../gcc/cp/parser.c:20647
0x9ab915 cp_parser_type_id
	../../gcc/cp/parser.c:20715
0x98fc43 cp_parser_postfix_expression
	../../gcc/cp/parser.c:6728
0x9935b1 cp_parser_unary_expression
	../../gcc/cp/parser.c:8125
0x9943e3 cp_parser_cast_expression
	../../gcc/cp/parser.c:8802
0x9944d3 cp_parser_binary_expression
	../../gcc/cp/parser.c:8903
0x9951ee cp_parser_assignment_expression
	../../gcc/cp/parser.c:9190
0x995949 cp_parser_constant_expression
	../../gcc/cp/parser.c:9460
0x9a6277 cp_parser_enumerator_definition
	../../gcc/cp/parser.c:18081
0x9a6133 cp_parser_enumerator_list
	../../gcc/cp/parser.c:18021
0x9a5ed0 cp_parser_enum_specifier
	../../gcc/cp/parser.c:17948
0x9a2e5b cp_parser_type_specifier
	../../gcc/cp/parser.c:16413
0x99dd17 cp_parser_decl_specifier_seq
	../../gcc/cp/parser.c:13352
Comment 1 Marek Polacek 2017-02-21 12:58:05 UTC
Confirmed.  Testcase:

enum E { a = (__underlying_type (E)) {} };
Comment 2 Marek Polacek 2017-02-21 12:59:41 UTC
$ clang++ -c u.cc
u.cc:1:15: error: cannot determine underlying type of incomplete enumeration type 'E'
enum E { a = (__underlying_type (E)) {} };
              ^
u.cc:1:6: note: forward declaration of 'E'
enum E { a = (__underlying_type (E)) {} };
     ^
u.cc:1:38: error: expression is not an integral constant expression
enum E { a = (__underlying_type (E)) {} };
                                     ^~
2 errors generated.


but we just segv:

$ ./cc1plus -quiet u.cc -Wall -Wpedantic
u.cc:1:35: internal compiler error: Segmentation fault
 enum E { a = (__underlying_type (E)) {} };
                                   ^
Comment 3 Marek Polacek 2017-02-21 13:01:29 UTC
$ xg++-46 -c u.cc -std=c++0x
u.cc:1:35: error: expected primary-expression before ‘)’ token
u.cc:1:35: error: ‘__underlying_type’ was not declared in this scope
u.cc:1:38: error: expected ‘}’ before ‘{’ token
u.cc:1:38: error: expected unqualified-id before ‘{’ token
u.cc:1:41: error: expected declaration before ‘}’ token

and since g++4.7 we ICE.
Comment 4 Marek Polacek 2017-02-22 19:33:45 UTC
Author: mpolacek
Date: Wed Feb 22 19:33:13 2017
New Revision: 245658

URL: https://gcc.gnu.org/viewcvs?rev=245658&root=gcc&view=rev
Log:
	PR c++/79657
	* semantics.c (finish_underlying_type): Bail out for incomplete enums.

	* g++.dg/ext/underlying_type12.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/underlying_type12.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2017-02-22 19:35:11 UTC
Fixed for GCC 7.