10796 – [3.3/3.4 regression] ICE (segfault) when defining an enum with two values: -1 and MAX_INT_64BIT (original) (raw)

| In C++, according to Stroustrup, enums can grow to sizeof(int). On this machine, sizeof(int)==4, but I when exploring the maximum size enum value g++ would honour, I got an ICE. The following code (put it in a file called enum.C) COMPILES with given command line and runs $ cat enum.C <<EOF enum test { acceptable = 0x7fffffffffffffff, unacceptable = 0xffffffffffffffff }; int main() { test t = acceptable, u = unacceptable; return 0; } EOF $ g++ -save-temps enum.C -o enum $ ./enum Release: 3.3 and 3.4 (CVS 20030503) Environment: Linux 2.4.18-17.7.x i686 How-To-Repeat: Replace line in enum.C that says: acceptable = 0x7fffffffffffffff, with the following line: acceptable = -1, and attempt to compile with command line as given. Comment 1 kevin 2003-05-15 07:26:00 UTC Fix: Don't use ridiculous enum values? Is that sufficient, or should the compiler be able to pick this up? Comment 2 Giovanni Bajo 2003-05-15 10:40:02 UTC State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. To make it clearer, the following code snippet ICEs GCC: ------------------------------------------------ enum test { one = -1, two = 0xffffffffffffffff }; ------------------------------------------------ pr10796.cpp:4: error: integer constant is too large for "long" type pr10796.cpp:5: internal compiler error: Segmentation fault Please submit a full bug report, I call the code legal because it would be possible to use "unsigned long long" as underlying type for such an enumerator (at least on x86, where its size is 8 bytes), even if I don't know what the C++ ABI says about this. Anyway, we shouldn't segfault on this for sure. It's a regression wrt 2.95 (which was failing gracefully). Comment 3 Drea Pinski 2003-06-07 19:30:51 UTC It still fails on the mainline (20030607): 0x080820ad in finish_enum (enumtype=0x400a83cc) at /home/gates/pinskia/src/gnu/ gcc/src/gcc/cp/decl.c:13100 warning: Source file is more recent than executable. 13100 layout_type (enumtype); (gdb) bt #0 0x080820ad in finish_enum (enumtype=0x400a83cc) at /home/gates/pinskia/src/ gnu/gcc/src/gcc/cp/decl.c:13100 #1 0x080fe776 in cp_parser_enum_specifier (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:8995 #2 0x080fe09c in cp_parser_type_specifier (parser=0x400aa480, flags= CP_PARSER_FLAGS_OPTIONAL, is_friend=false, is_declaration=true, declares_class_or_enum=0xbffec2fe, is_cv_qualifier=0xbffec2ff) at /home/gates/pinskia/ src/gnu/gcc/src/gcc/cp/parser.c:8470 #3 0x080fc5ad in cp_parser_decl_specifier_seq (parser=0x400aa480, flags= CP_PARSER_FLAGS_OPTIONAL, attributes=0xbffec348, declares_class_or_enum= 0xbffec34f) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6802 #4 0x080fc2ac in cp_parser_simple_declaration (parser=0x400aa480, function_definition_allowed_p=true) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/ parser.c:6548 #5 0x080fc1d4 in cp_parser_block_declaration (parser=0x400aa480, statement_p= false) at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6508 #6 0x080fc08d in cp_parser_declaration (parser=0x400aa480) at /home/gates/pinskia/ src/gnu/gcc/src/gcc/cp/parser.c:6428 #7 0x080fbf38 in cp_parser_declaration_seq_opt (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:6337 #8 0x080f7962 in cp_parser_translation_unit (parser=0x400aa480) at /home/gates/ pinskia/src/gnu/gcc/src/gcc/cp/parser.c:2256 #9 0x08105592 in yyparse () at /home/gates/pinskia/src/gnu/gcc/src/gcc/cp/ parser.c:14671 #10 0x0817da76 in c_common_parse_file (set_yydebug=0) at /home/gates/pinskia/src/ gnu/gcc/src/gcc/c-opts.c:1394 #11 0x083aab3a in compile_file () at /home/gates/pinskia/src/gnu/gcc/src/gcc/ toplev.c:2213 #12 0x083b0c77 in do_compile () at /home/gates/pinskia/src/gnu/gcc/src/gcc/ toplev.c:5743 #13 0x083b0ce9 in toplev_main (argc=0, argv=0x0) at /home/gates/pinskia/src/gnu/gcc/ src/gcc/toplev.c:5772 #14 0x081819eb in main (argc=0, argv=0x0) at /home/gates/pinskia/src/gnu/gcc/src/gcc/ main.c:37 (gdb) p debug_tree(enumtype) <enumeral_type 0x400a83cc test TI size <integer_cst 0x4004eb18 type <integer_type 0x4005a948 bit_size_type> constant 128> unit size <integer_cst 0x4004eb2c type <integer_type 0x4005a8dc unsigned int> constant 16> align 128 symtab 0 alias set -1 precision 65 min <integer_cst 0x400ad050 0x8000000000000000> max <integer_cst 0x400ad064 0x7fffffffffffffff> values <tree_list 0x40099fa0 purpose <identifier_node 0x400aa500 onebindings <0x40099f8c>local bindings < (nil)>> value <integer_cst 0x400ad000 constant tree_0 -1> chain <tree_list 0x40099fdc purpose <identifier_node 0x400aa540 twobindings <0x40099fc8>local bindings < (nil)>> value <integer_cst 0x400ad014 constant -1>>> chain <type_decl 0x400a8438 test>> Comment 6 Mark Mitchell 2003-06-27 21:41:32 UTC Fixed in GCC 3.3.1, GCC 3.4. | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |