https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82650
Bug ID: 82650 Summary: -fdump-go-spec Segmentation fault on enums Product: gcc Version: 6.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: avshash at hotmail dot com Target Milestone: --- Using the '-fdump-go-spec' flag causes Segmentation fault when program has any enum definition on c++ files. Example: --------------------------------------------------- enum dummy_t { DUMMY_ENUM }; int main () { return 0 } ---------------------------------------------------- command line - g++ main.cc -fdump-go-spec=dummy.go ---------------------------------------------------- reason is the difference in enum tree between C and C++ Patch in 'godump.c', function 'go_output_typedef' (correct fix should be a proper function) ----------------------------------------------------- ADD: tree integer_cst = TREE_VALUE (element); if (TREE_CODE (integer_cst) == CONST_DECL) { integer_cst = DECL_INITIAL (integer_cst); } if (TREE_CODE (integer_cst) != INTEGER_CST) { internal_error ("..."); } CHANGE: if (tree_fits_shwi_p (integer_cst)) { // CHANGE ^^^^^^^^^^^ snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_DEC, tree_to_shwi (integer_cst)); // CHANGE ^^^^^^^^^^^ } else if (tree_fits_uhwi_p (integer_cst)) { // CHANGE ^^^^^^^^^^^ snprintf (buf, sizeof (buf), HOST_WIDE_INT_PRINT_UNSIGNED, tree_to_uhwi (integer_cst)); // CHANGE ^^^^^^^^^^^ } else { print_hex (wi::to_wide (integer_cst, buf)); // CHANGE ^^^^^^^^^^^ // the last one is also a bug in the C branch, // where there is a 'TREE_VALUE' missing // but unreachable code on my machine. }