From 8dc2b10365a3d9def1a6e0412db0cc0177cfad6d Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 30 Aug 2004 15:28:48 +0000 Subject: [PATCH] call.c (check_dtor_name): Replace abort with gcc_assert or gcc_unreachable. * call.c (check_dtor_name): Replace abort with gcc_assert or gcc_unreachable. (build_call, add_builtin_candidate, build_new_op, convert_like_real, build_over_call, in_charge_arg_for_name, source_type, joust): Likewise. * class.c (build_simple_base_path, get_vcall_index, finish_struct_1, instantiate_type, get_enclosing_class, add_vcall_offset_vtbl_entries_1, cp_fold_obj_type_ref): Likewise. * cp-gimplify.c (cp_genericize): Likewise. * cp-lang.c (cp_expr_size, cp_tree_size): Likewise. * cvt.c (cp_convert_to_pointer, ocp_convert): Likewise. * decl.c (poplevel, make_unbound_class_template, reshape_init, check_special_function_return_type, grokdeclarator, grok_op_properties, tag_name, xref_tag, start_preparsed_function, finish_function): Likewise. * decl2.c (grokfield, maybe_emit_vtables):Likewise. * error.c (dump_global_iord, dump_decl, dump_template_decl, language_to_string): Likewise. * except.c (choose_personality_routine): Likewise. * friend.c (do_friend): Likewise. * g++spec.c (lang_specific_driver): Likewise. * init.c (build_zero_init, expand_default_init, build_new_1, build_vec_delete_1, build_vec_init, build_dtor_call): Likewise. * lex.c (retrofit_lang_decl, cp_type_qual_from_rid): Likewise. * mangle.c (add_substitution, write_unscoped_name, write_template_prefix, write_identifier, write_special_name_destructor, write_type, write_builtin_type, write_expression, write_template_param, write_java_integer_type_codes): Likewise. * method.c (implicitly_declare_fn): Likewise. From-SVN: r86778 --- gcc/cp/ChangeLog | 33 +++++++++++ gcc/cp/call.c | 80 ++++++++++++++------------- gcc/cp/class.c | 34 +++++------- gcc/cp/cp-gimplify.c | 6 +- gcc/cp/cp-lang.c | 14 ++--- gcc/cp/cvt.c | 27 ++++----- gcc/cp/decl.c | 50 ++++++++--------- gcc/cp/decl2.c | 23 ++++---- gcc/cp/error.c | 34 ++++++------ gcc/cp/except.c | 2 +- gcc/cp/friend.c | 3 +- gcc/cp/g++spec.c | 2 +- gcc/cp/init.c | 20 +++---- gcc/cp/lex.c | 5 +- gcc/cp/mangle.c | 128 +++++++++++++++++++++---------------------- gcc/cp/method.c | 5 +- 16 files changed, 243 insertions(+), 223 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fc1afbcb0a7..78e651b0d98 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,36 @@ +2004-08-30 Nathan Sidwell + + * call.c (check_dtor_name): Replace abort with gcc_assert or + gcc_unreachable. + (build_call, add_builtin_candidate, build_new_op, + convert_like_real, build_over_call, in_charge_arg_for_name, + source_type, joust): Likewise. + * class.c (build_simple_base_path, get_vcall_index, + finish_struct_1, instantiate_type, get_enclosing_class, + add_vcall_offset_vtbl_entries_1, cp_fold_obj_type_ref): Likewise. + * cp-gimplify.c (cp_genericize): Likewise. + * cp-lang.c (cp_expr_size, cp_tree_size): Likewise. + * cvt.c (cp_convert_to_pointer, ocp_convert): Likewise. + * decl.c (poplevel, make_unbound_class_template, reshape_init, + check_special_function_return_type, grokdeclarator, + grok_op_properties, tag_name, xref_tag, start_preparsed_function, + finish_function): Likewise. + * decl2.c (grokfield, maybe_emit_vtables):Likewise. + * error.c (dump_global_iord, dump_decl, dump_template_decl, + language_to_string): Likewise. + * except.c (choose_personality_routine): Likewise. + * friend.c (do_friend): Likewise. + * g++spec.c (lang_specific_driver): Likewise. + * init.c (build_zero_init, expand_default_init, build_new_1, + build_vec_delete_1, build_vec_init, build_dtor_call): Likewise. + * lex.c (retrofit_lang_decl, cp_type_qual_from_rid): Likewise. + * mangle.c (add_substitution, write_unscoped_name, + write_template_prefix, write_identifier, + write_special_name_destructor, write_type, write_builtin_type, + write_expression, write_template_param, + write_java_integer_type_codes): Likewise. + * method.c (implicitly_declare_fn): Likewise. + 2004-08-30 Nathan Sidwell * cp-tree.h (BINFO_PRIMARY_P): Use a binfo flag. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 07aea66308b..4e5b3d590c1 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -234,17 +234,18 @@ check_dtor_name (tree basetype, tree name) else name = get_type_value (name); } - /* In the case of: - - template struct S { ~S(); }; - int i; - i.~S(); - - NAME will be a class template. */ - else if (DECL_CLASS_TEMPLATE_P (name)) - return false; else - abort (); + { + /* In the case of: + + template struct S { ~S(); }; + int i; + i.~S(); + + NAME will be a class template. */ + gcc_assert (DECL_CLASS_TEMPLATE_P (name)); + return false; + } if (name && TYPE_MAIN_VARIANT (basetype) == TYPE_MAIN_VARIANT (name)) return true; @@ -328,11 +329,10 @@ build_call (tree function, tree parms) /* We invoke build_call directly for several library functions. These may have been declared normally if we're building libgcc, so we can't just check DECL_ARTIFICIAL. */ - if (DECL_ARTIFICIAL (decl) - || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "__", 2)) - mark_used (decl); - else - abort (); + gcc_assert (DECL_ARTIFICIAL (decl) + || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), + "__", 2)); + mark_used (decl); } /* Don't pass empty class objects by value. This is useful @@ -1915,7 +1915,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, return; default: - abort (); + gcc_unreachable (); } type1 = build_reference_type (type1); break; @@ -1952,7 +1952,7 @@ add_builtin_candidate (struct z_candidate **candidates, enum tree_code code, break; default: - abort (); + gcc_unreachable (); } /* If we're dealing with two pointer types or two enumeral types, @@ -3600,7 +3600,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, case VEC_DELETE_EXPR: case DELETE_EXPR: /* Use build_op_new_call and build_op_delete_call instead. */ - abort (); + gcc_unreachable (); case CALL_EXPR: return build_object_call (arg1, arg2); @@ -3836,7 +3836,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, if (result || result_valid_p) return result; -builtin: + builtin: switch (code) { case MODIFY_EXPR: @@ -3895,9 +3895,9 @@ builtin: return NULL_TREE; default: - abort (); - return NULL_TREE; + gcc_unreachable (); } + return NULL_TREE; } /* Build a call to operator delete. This has to be handled very specially, @@ -4180,11 +4180,10 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, 0); args = build_tree_list (NULL_TREE, expr); - if (DECL_HAS_IN_CHARGE_PARM_P (convfn) - || DECL_HAS_VTT_PARM_P (convfn)) - /* We should never try to call the abstract or base constructor - from here. */ - abort (); + /* We should never try to call the abstract or base constructor + from here. */ + gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (convfn) + && !DECL_HAS_VTT_PARM_P (convfn)); args = tree_cons (NULL_TREE, t, args); } else @@ -4649,9 +4648,9 @@ build_over_call (struct z_candidate *cand, int flags) converted_args = tree_cons (NULL_TREE, TREE_VALUE (arg), converted_args); arg = TREE_CHAIN (arg); parm = TREE_CHAIN (parm); - if (DECL_HAS_IN_CHARGE_PARM_P (fn)) - /* We should never try to call the abstract constructor. */ - abort (); + /* We should never try to call the abstract constructor. */ + gcc_assert (!DECL_HAS_IN_CHARGE_PARM_P (fn)); + if (DECL_HAS_VTT_PARM_P (fn)) { converted_args = tree_cons @@ -4967,12 +4966,14 @@ build_java_interface_fn_ref (tree fn, tree instance) } /* Returns the value to use for the in-charge parameter when making a - call to a function with the indicated NAME. */ + call to a function with the indicated NAME. + + FIXME:Can't we find a neater way to do this mapping? */ tree in_charge_arg_for_name (tree name) { - if (name == base_ctor_identifier + if (name == base_ctor_identifier || name == base_dtor_identifier) return integer_zero_node; else if (name == complete_ctor_identifier) @@ -4984,7 +4985,7 @@ in_charge_arg_for_name (tree name) /* This function should only be called with one of the names listed above. */ - abort (); + gcc_unreachable (); return NULL_TREE; } @@ -5838,7 +5839,7 @@ source_type (conversion *t) || t->kind == ck_identity) return t->type; } - abort (); + gcc_unreachable (); } /* Note a warning about preferring WINNER to LOSER. We do this by storing @@ -5899,17 +5900,18 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn) len = cand1->num_convs; if (len != cand2->num_convs) { - if (DECL_STATIC_FUNCTION_P (cand1->fn) - && ! DECL_STATIC_FUNCTION_P (cand2->fn)) + int static_1 = DECL_STATIC_FUNCTION_P (cand1->fn); + int static_2 = DECL_STATIC_FUNCTION_P (cand2->fn); + + gcc_assert (static_1 != static_2); + + if (static_1) off2 = 1; - else if (! DECL_STATIC_FUNCTION_P (cand1->fn) - && DECL_STATIC_FUNCTION_P (cand2->fn)) + else { off1 = 1; --len; } - else - abort (); } for (i = 0; i < len; ++i) diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1007ebbc289..22781e3c331 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -418,8 +418,7 @@ build_simple_base_path (tree expr, tree binfo) if (d_binfo == NULL_TREE) { - if (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) != type) - abort (); + gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type); return expr; } @@ -436,7 +435,7 @@ build_simple_base_path (tree expr, tree binfo) NULL_TREE, false); /* Didn't find the base field?!? */ - abort (); + gcc_unreachable (); } /* Convert OBJECT to the base TYPE. If CHECK_ACCESS is true, an error @@ -2007,9 +2006,7 @@ get_vcall_index (tree fn, tree type) return p->value; /* There should always be an appropriate index. */ - abort (); - - return NULL_TREE; + gcc_unreachable (); } /* Update an entry in the vtable for BINFO, which is in the hierarchy @@ -4928,10 +4925,8 @@ finish_struct_1 (tree t) if (COMPLETE_TYPE_P (t)) { - if (IS_AGGR_TYPE (t)) - error ("redefinition of `%#T'", t); - else - abort (); + gcc_assert (IS_AGGR_TYPE (t)); + error ("redefinition of `%#T'", t); popclass (); return; } @@ -5942,8 +5937,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) case CONVERT_EXPR: case SAVE_EXPR: case CONSTRUCTOR: - abort (); - return error_mark_node; + gcc_unreachable (); case INDIRECT_REF: case ARRAY_REF: @@ -6014,8 +6008,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) case CALL_EXPR: /* This is too hard for now. */ - abort (); - return error_mark_node; + gcc_unreachable (); case PLUS_EXPR: case MINUS_EXPR: @@ -6124,9 +6117,9 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) return error_mark_node; default: - abort (); - return error_mark_node; + gcc_unreachable (); } + return error_mark_node; } /* Return the name of the virtual function pointer field @@ -6273,7 +6266,7 @@ get_enclosing_class (tree type) break; default: - abort (); + gcc_unreachable (); } } return NULL_TREE; @@ -7604,8 +7597,7 @@ add_vcall_offset_vtbl_entries_1 (tree binfo, vtbl_init_data* vid) might be a lost primary, so just skip down to vid->binfo. */ if (BINFO_VIRTUAL_P (non_primary_binfo)) { - if (non_primary_binfo != vid->vbase) - abort (); + gcc_assert (non_primary_binfo == vid->vbase); non_primary_binfo = vid->binfo; break; } @@ -7794,8 +7786,8 @@ cp_fold_obj_type_ref (tree ref, tree known_type) fndecl = BV_FN (v); #ifdef ENABLE_CHECKING - if (!tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref), DECL_VINDEX (fndecl))) - abort (); + gcc_assert (tree_int_cst_equal (OBJ_TYPE_REF_TOKEN (ref), + DECL_VINDEX (fndecl))); #endif return build_address (fndecl); diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index d9fc928529c..c937a1149d3 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -329,12 +329,10 @@ cp_genericize (tree fndecl) /* Fix up the types of parms passed by invisible reference. */ for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) { - if (DECL_BY_REFERENCE (t)) - abort (); + gcc_assert (!DECL_BY_REFERENCE (t)); if (TREE_ADDRESSABLE (TREE_TYPE (t))) { - if (DECL_ARG_TYPE (t) == TREE_TYPE (t)) - abort (); + gcc_assert (DECL_ARG_TYPE (t) != TREE_TYPE (t)); TREE_TYPE (t) = DECL_ARG_TYPE (t); DECL_BY_REFERENCE (t) = 1; TREE_ADDRESSABLE (t) = 0; diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c index 00ba81cf8a5..a1359cd7c86 100644 --- a/gcc/cp/cp-lang.c +++ b/gcc/cp/cp-lang.c @@ -260,13 +260,13 @@ cp_expr_size (tree exp) /* The backend should not be interested in the size of an expression of a type with both of these set; all copies of such types must go through a constructor or assignment op. */ - if (TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp)) - && TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)) - /* But storing a CONSTRUCTOR isn't a copy. */ - && TREE_CODE (exp) != CONSTRUCTOR) - abort (); + gcc_assert (!TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp)) + || !TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)) + /* But storing a CONSTRUCTOR isn't a copy. */ + || TREE_CODE (exp) == CONSTRUCTOR); + /* This would be wrong for a type with virtual bases, but they are - caught by the abort above. */ + caught by the assert above. */ return (is_empty_class (TREE_TYPE (exp)) ? size_zero_node : CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp))); @@ -289,7 +289,7 @@ cp_tree_size (enum tree_code code) case DEFAULT_ARG: return sizeof (struct tree_default_arg); case OVERLOAD: return sizeof (struct tree_overload); default: - abort (); + gcc_unreachable (); } /* NOTREACHED */ } diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index ed18d7c53f7..cb179d55ab2 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -284,12 +284,12 @@ cp_convert_to_pointer (tree type, tree expr, bool force) if (TYPE_PRECISION (intype) == POINTER_SIZE) return build1 (CONVERT_EXPR, type, expr); expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr); - /* Modes may be different but sizes should be the same. */ - if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr))) - != GET_MODE_SIZE (TYPE_MODE (type))) - /* There is supposed to be some integral type - that is the same width as a pointer. */ - abort (); + /* Modes may be different but sizes should be the same. There + is supposed to be some integral type that is the same width + as a pointer. */ + gcc_assert (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr))) + == GET_MODE_SIZE (TYPE_MODE (type))); + return convert_to_pointer (type, expr); } @@ -647,17 +647,18 @@ ocp_convert (tree type, tree expr, int convtype, int flags) /* Don't build a NOP_EXPR of class type. Instead, change the type of the temporary. Only allow this for cv-qual changes, though. */ - if (!same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (e)), - TYPE_MAIN_VARIANT (type))) - abort (); + gcc_assert (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (e)), + TYPE_MAIN_VARIANT (type))); TREE_TYPE (e) = TREE_TYPE (TARGET_EXPR_SLOT (e)) = type; return e; } - else if (TREE_ADDRESSABLE (type)) - /* We shouldn't be treating objects of ADDRESSABLE type as rvalues. */ - abort (); else - return fold (build1 (NOP_EXPR, type, e)); + { + /* We shouldn't be treating objects of ADDRESSABLE type as + rvalues. */ + gcc_assert (!TREE_ADDRESSABLE (type)); + return fold (build1 (NOP_EXPR, type, e)); + } } if (code == VOID_TYPE && (convtype & CONV_STATIC)) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2265d4e2b26..bd7098289b2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -602,18 +602,20 @@ poplevel (int keep, int reverse, int functionbody) } else { + tree name; + /* Remove the binding. */ decl = link; if (TREE_CODE (decl) == TREE_LIST) decl = TREE_VALUE (decl); + name = decl; + + if (TREE_CODE (name) == OVERLOAD) + name = OVL_FUNCTION (name); - if (DECL_P (decl)) - pop_binding (DECL_NAME (decl), decl); - else if (TREE_CODE (decl) == OVERLOAD) - pop_binding (DECL_NAME (OVL_FUNCTION (decl)), decl); - else - abort (); + gcc_assert (DECL_P (name)); + pop_binding (DECL_NAME (name), decl); } } @@ -2702,8 +2704,7 @@ make_unbound_class_template (tree context, tree name, tsubst_flags_t complain) name = TYPE_IDENTIFIER (name); else if (DECL_P (name)) name = DECL_NAME (name); - if (TREE_CODE (name) != IDENTIFIER_NODE) - abort (); + gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE); if (!dependent_type_p (context) || currently_open_class (context)) @@ -4324,7 +4325,7 @@ reshape_init (tree type, tree *initp) } } else - abort (); + gcc_unreachable (); /* The initializers were placed in reverse order in the CONSTRUCTOR. */ @@ -6258,8 +6259,7 @@ check_special_function_return_type (special_function_kind sfk, break; default: - abort (); - break; + gcc_unreachable (); } return type; @@ -6493,7 +6493,7 @@ grokdeclarator (const cp_declarator *declarator, break; default: - abort (); + gcc_unreachable (); } break; @@ -6507,7 +6507,7 @@ grokdeclarator (const cp_declarator *declarator, break; default: - abort (); + gcc_unreachable (); } } if (id_declarator->kind == cdk_id) @@ -6982,7 +6982,7 @@ grokdeclarator (const cp_declarator *declarator, break; default: - abort (); + gcc_unreachable (); } } @@ -7236,7 +7236,7 @@ grokdeclarator (const cp_declarator *declarator, break; default: - abort (); + gcc_unreachable (); } } @@ -7619,10 +7619,8 @@ grokdeclarator (const cp_declarator *declarator, error ("unnamed variable or field declared void"); else if (TREE_CODE (unqualified_id) == IDENTIFIER_NODE) { - if (IDENTIFIER_OPNAME_P (unqualified_id)) - abort (); - else - error ("variable or field `%s' declared void", name); + gcc_assert (!IDENTIFIER_OPNAME_P (unqualified_id)); + error ("variable or field `%s' declared void", name); } else error ("variable or field declared void"); @@ -8524,7 +8522,7 @@ grok_op_properties (tree decl, int friendp, bool complain) #include "operators.def" #undef DEF_OPERATOR - abort (); + gcc_unreachable (); } while (0); gcc_assert (operator_code != LAST_CPLUS_TREE_CODE); @@ -8694,7 +8692,7 @@ grok_op_properties (tree decl, int friendp, bool complain) break; default: - abort (); + gcc_unreachable (); } SET_OVERLOADED_OPERATOR_CODE (decl, operator_code); @@ -8825,7 +8823,7 @@ tag_name (enum tag_types code) case enum_type: return "enum"; default: - abort (); + gcc_unreachable (); } } @@ -8946,7 +8944,7 @@ xref_tag (enum tag_types tag_code, tree name, code = ENUMERAL_TYPE; break; default: - abort (); + gcc_unreachable (); } if (! globalize) @@ -9845,8 +9843,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags) } if (DECL_HAS_VTT_PARM_P (decl1)) { - if (DECL_NAME (t) != vtt_parm_identifier) - abort (); + gcc_assert (DECL_NAME (t) == vtt_parm_identifier); current_vtt_parm = t; } } @@ -10356,8 +10353,7 @@ finish_function (int flags) if (current_binding_level->kind != sk_function_parms) { /* Make sure we have already experienced errors. */ - if (errorcount == 0) - abort (); + gcc_assert (errorcount); /* Throw away the broken statement tree and extra binding levels. */ diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 2d852f71481..5e0651e79bd 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -953,14 +953,14 @@ grokfield (const cp_declarator *declarator, if (attrlist) cplus_decl_attributes (&value, attrlist, 0); - if (TREE_CODE (value) == VAR_DECL) + switch (TREE_CODE (value)) { + case VAR_DECL: finish_static_data_member_decl (value, init, asmspec_tree, flags); return value; - } - if (TREE_CODE (value) == FIELD_DECL) - { + + case FIELD_DECL: if (asmspec) error ("`asm' specifiers are not permitted on non-static data members"); if (DECL_INITIAL (value) == error_mark_node) @@ -969,9 +969,8 @@ grokfield (const cp_declarator *declarator, DECL_INITIAL (value) = init; DECL_IN_AGGR_P (value) = 1; return value; - } - if (TREE_CODE (value) == FUNCTION_DECL) - { + + case FUNCTION_DECL: if (asmspec) set_user_assembler_name (value, asmspec); if (!DECL_FRIEND_P (value)) @@ -985,9 +984,10 @@ grokfield (const cp_declarator *declarator, DECL_IN_AGGR_P (value) = 1; return value; + + default: + gcc_unreachable (); } - abort (); - /* NOTREACHED */ return NULL_TREE; } @@ -1586,9 +1586,10 @@ maybe_emit_vtables (tree ctype) if (TREE_TYPE (DECL_INITIAL (vtbl)) == 0) { + tree expr = store_init_value (vtbl, DECL_INITIAL (vtbl)); + /* It had better be all done at compile-time. */ - if (store_init_value (vtbl, DECL_INITIAL (vtbl))) - abort (); + gcc_assert (!expr); } /* Write it out. */ diff --git a/gcc/cp/error.c b/gcc/cp/error.c index dabac033108..03feaf3b7da 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -677,7 +677,7 @@ dump_global_iord (tree t) else if (DECL_GLOBAL_DTOR_P (t)) p = "destructors"; else - abort (); + gcc_unreachable (); pp_printf (pp_base (cxx_pp), "(static %s for %s)", p, input_filename); } @@ -790,7 +790,7 @@ dump_decl (tree t, int flags) break; case TYPE_EXPR: - abort (); + gcc_unreachable (); break; /* These special cases are duplicated here so that other functions @@ -954,20 +954,22 @@ dump_template_decl (tree t, int flags) | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0))); else if (TREE_CODE (DECL_TEMPLATE_RESULT (t)) == VAR_DECL) dump_decl (DECL_TEMPLATE_RESULT (t), flags | TFF_TEMPLATE_NAME); - else if (TREE_TYPE (t) == NULL_TREE) - abort (); else - switch (NEXT_CODE (t)) { - case METHOD_TYPE: - case FUNCTION_TYPE: - dump_function_decl (t, flags | TFF_TEMPLATE_NAME); - break; - default: - /* This case can occur with some invalid code. */ - dump_type (TREE_TYPE (t), - (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME - | (flags & TFF_DECL_SPECIFIERS ? TFF_CLASS_KEY_OR_ENUM : 0)); + gcc_assert (TREE_TYPE (t)); + switch (NEXT_CODE (t)) + { + case METHOD_TYPE: + case FUNCTION_TYPE: + dump_function_decl (t, flags | TFF_TEMPLATE_NAME); + break; + default: + /* This case can occur with some invalid code. */ + dump_type (TREE_TYPE (t), + (flags & ~TFF_CLASS_KEY_OR_ENUM) | TFF_TEMPLATE_NAME + | (flags & TFF_DECL_SPECIFIERS + ? TFF_CLASS_KEY_OR_ENUM : 0)); + } } } @@ -2027,9 +2029,9 @@ language_to_string (enum languages c) return "Java"; default: - abort (); - return 0; + gcc_unreachable (); } + return 0; } /* Return the proper printed version of a parameter to a C++ function. */ diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 72ce2867d29..31bf96b780d 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -312,7 +312,7 @@ choose_personality_routine (enum languages lang) break; default: - abort (); + gcc_unreachable (); } return; diff --git a/gcc/cp/friend.c b/gcc/cp/friend.c index 75551a9678e..1310a93d02b 100644 --- a/gcc/cp/friend.c +++ b/gcc/cp/friend.c @@ -337,8 +337,7 @@ do_friend (tree ctype, tree declarator, tree decl, declarator = DECL_NAME (get_first_fn (declarator)); } - if (TREE_CODE (decl) != FUNCTION_DECL) - abort (); + gcc_assert (TREE_CODE (decl) == FUNCTION_DECL); if (ctype) { diff --git a/gcc/cp/g++spec.c b/gcc/cp/g++spec.c index ec31d818805..16441400b34 100644 --- a/gcc/cp/g++spec.c +++ b/gcc/cp/g++spec.c @@ -293,7 +293,7 @@ lang_specific_driver (int *in_argc, const char *const **in_argv, arglist[j++] = "-xc++-header"; break; default: - abort (); + gcc_unreachable (); } arglist[j++] = argv[i]; arglist[j] = "-xnone"; diff --git a/gcc/cp/init.c b/gcc/cp/init.c index ea38333d776..01478818b27 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -240,10 +240,8 @@ build_zero_init (tree type, tree nelts, bool static_storage_p) inits); CONSTRUCTOR_ELTS (init) = nreverse (inits); } - else if (TREE_CODE (type) == REFERENCE_TYPE) - ; else - abort (); + gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); /* In all cases, the initializer is a constant. */ if (init) @@ -1166,8 +1164,7 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags) && (flags & LOOKUP_ONLYCONVERTING)) { /* Base subobjects should only get direct-initialization. */ - if (true_exp != exp) - abort (); + gcc_assert (true_exp == exp); if (flags & DIRECT_BIND) /* Do nothing. We hit this in two cases: Reference initialization, @@ -2073,9 +2070,9 @@ build_new_1 (tree exp) if (TREE_CODE (init) == TREE_LIST) init = build_x_compound_expr_from_list (init, "new initializer"); - else if (TREE_CODE (init) == CONSTRUCTOR - && TREE_TYPE (init) == NULL_TREE) - abort (); + else + gcc_assert (TREE_CODE (init) != CONSTRUCTOR + || TREE_TYPE (init) != NULL_TREE); init_expr = build_modify_expr (init_expr, INIT_EXPR, init); stable = stabilize_init (init_expr, &init_preeval_expr); @@ -2217,8 +2214,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree type, tree controller = NULL_TREE; /* We should only have 1-D arrays here. */ - if (TREE_CODE (type) == ARRAY_TYPE) - abort (); + gcc_assert (TREE_CODE (type) != ARRAY_TYPE); if (! IS_AGGR_TYPE (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) goto no_destructor; @@ -2560,7 +2556,7 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array) else if (from) elt_init = build_modify_expr (to, NOP_EXPR, from); else - abort (); + gcc_unreachable (); } else if (TREE_CODE (type) == ARRAY_TYPE) { @@ -2670,7 +2666,7 @@ build_dtor_call (tree exp, special_function_kind dtor_kind, int flags) break; default: - abort (); + gcc_unreachable (); } exp = convert_from_reference (exp); diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index fc0a5abb5c3..468585edef5 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -687,7 +687,8 @@ retrofit_lang_decl (tree t) SET_DECL_LANGUAGE (t, lang_c); else if (current_lang_name == lang_name_java) SET_DECL_LANGUAGE (t, lang_java); - else abort (); + else + gcc_unreachable (); #ifdef GATHER_STATISTICS tree_node_counts[(int)lang_decl] += 1; @@ -826,6 +827,6 @@ cp_type_qual_from_rid (tree rid) else if (rid == ridpointers[(int) RID_RESTRICT]) return TYPE_QUAL_RESTRICT; - abort (); + gcc_unreachable (); return TYPE_UNQUALIFIED; } diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index d1a5766f2ab..b6253b27b88 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -373,12 +373,10 @@ add_substitution (tree node) for (i = VARRAY_ACTIVE_SIZE (G.substitutions); --i >= 0; ) { const tree candidate = VARRAY_TREE (G.substitutions, i); - if ((DECL_P (node) - && node == candidate) - || (TYPE_P (node) - && TYPE_P (candidate) - && same_type_p (node, candidate))) - abort (); + + gcc_assert (!(DECL_P (node) && node == candidate)); + gcc_assert (!(TYPE_P (node) && TYPE_P (candidate) + && same_type_p (node, candidate))); } } #endif /* ENABLE_CHECKING */ @@ -832,14 +830,16 @@ write_unscoped_name (const tree decl) write_string ("St"); write_unqualified_name (decl); } - /* If not, it should be either in the global namespace, or directly - in a local function scope. */ - else if (context == global_namespace - || context == NULL - || TREE_CODE (context) == FUNCTION_DECL) - write_unqualified_name (decl); - else - abort (); + else + { + /* If not, it should be either in the global namespace, or directly + in a local function scope. */ + gcc_assert (context == global_namespace + || context == NULL + || TREE_CODE (context) == FUNCTION_DECL); + + write_unqualified_name (decl); + } } /* ::= @@ -984,11 +984,12 @@ write_template_prefix (const tree node) /* Find the template decl. */ if (decl_is_template_id (decl, &template_info)) template = TI_TEMPLATE (template_info); - else if (CLASSTYPE_TEMPLATE_ID_P (type)) - template = TYPE_TI_TEMPLATE (type); else - /* Oops, not a template. */ - abort (); + { + gcc_assert (CLASSTYPE_TEMPLATE_ID_P (type)); + + template = TYPE_TI_TEMPLATE (type); + } /* For a member template, though, the template name for the innermost name must have all the outer template levels @@ -1325,16 +1326,18 @@ write_identifier (const char *identifier) static void write_special_name_constructor (const tree ctor) { - if (DECL_COMPLETE_CONSTRUCTOR_P (ctor) - /* Even though we don't ever emit a definition of the - old-style destructor, we still have to consider entities - (like static variables) nested inside it. */ - || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor)) - write_string ("C1"); - else if (DECL_BASE_CONSTRUCTOR_P (ctor)) + if (DECL_BASE_CONSTRUCTOR_P (ctor)) write_string ("C2"); else - abort (); + { + gcc_assert (DECL_COMPLETE_CONSTRUCTOR_P (ctor) + /* Even though we don't ever emit a definition of + the old-style destructor, we still have to + consider entities (like static variables) nested + inside it. */ + || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (ctor)); + write_string ("C1"); + } } /* Handle destructor productions of non-terminal . @@ -1353,16 +1356,18 @@ write_special_name_destructor (const tree dtor) { if (DECL_DELETING_DESTRUCTOR_P (dtor)) write_string ("D0"); - else if (DECL_COMPLETE_DESTRUCTOR_P (dtor) - /* Even though we don't ever emit a definition of the - old-style destructor, we still have to consider entities - (like static variables) nested inside it. */ - || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor)) - write_string ("D1"); else if (DECL_BASE_DESTRUCTOR_P (dtor)) write_string ("D2"); else - abort (); + { + gcc_assert (DECL_COMPLETE_DESTRUCTOR_P (dtor) + /* Even though we don't ever emit a definition of + the old-style destructor, we still have to + consider entities (like static variables) nested + inside it. */ + || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (dtor)); + write_string ("D1"); + } } /* Return the discriminator for ENTITY appearing inside @@ -1590,7 +1595,7 @@ write_type (tree type) break; default: - abort (); + gcc_unreachable (); } } @@ -1706,11 +1711,8 @@ write_builtin_type (tree type) TYPE_UNSIGNED (type)); if (type == t) { - if (TYPE_PRECISION (type) == 128) - write_char (TYPE_UNSIGNED (type) ? 'o' : 'n'); - else - /* Couldn't find this type. */ - abort (); + gcc_assert (TYPE_PRECISION (type) == 128); + write_char (TYPE_UNSIGNED (type) ? 'o' : 'n'); } else { @@ -1731,11 +1733,11 @@ write_builtin_type (tree type) else if (type == long_double_type_node) write_char ('e'); else - abort (); + gcc_unreachable (); break; default: - abort (); + gcc_unreachable (); } } @@ -2139,31 +2141,29 @@ write_expression (tree expr) static void write_template_arg_literal (const tree value) { - tree type = TREE_TYPE (value); write_char ('L'); - write_type (type); + write_type (TREE_TYPE (value)); - if (TREE_CODE (value) == CONST_DECL) - write_integer_cst (DECL_INITIAL (value)); - else if (TREE_CODE (value) == INTEGER_CST) + switch (TREE_CODE (value)) { - if (same_type_p (type, boolean_type_node)) - { - if (integer_zerop (value)) - write_unsigned_number (0); - else if (integer_onep (value)) - write_unsigned_number (1); - else - abort (); - } - else - write_integer_cst (value); - } - else if (TREE_CODE (value) == REAL_CST) - write_real_cst (value); - else - abort (); + case CONST_DECL: + write_integer_cst (DECL_INITIAL (value)); + break; + + case INTEGER_CST: + gcc_assert (!same_type_p (TREE_TYPE (value), boolean_type_node) + || integer_zerop (value) || integer_onep (value)); + write_integer_cst (value); + break; + + case REAL_CST: + write_real_cst (value); + break; + default: + gcc_unreachable (); + } + write_char ('E'); } @@ -2352,7 +2352,7 @@ write_template_param (const tree parm) break; default: - abort (); + gcc_unreachable (); } write_char ('T'); @@ -2803,7 +2803,7 @@ write_java_integer_type_codes (const tree type) else if (type == java_boolean_type_node) write_char ('b'); else - abort (); + gcc_unreachable (); } #include "gt-cp-mangle.h" diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 2a7ddb5a50c..fe4cb1f0d1d 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -989,7 +989,7 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p) break; } default: - abort (); + gcc_unreachable (); } /* Create the function. */ @@ -1028,8 +1028,7 @@ implicitly_declare_fn (special_function_kind kind, tree type, bool const_p) DECL_NOT_REALLY_EXTERN (fn) = 1; DECL_DECLARED_INLINE_P (fn) = 1; DECL_INLINE (fn) = 1; - if (TREE_USED (fn)) - abort (); + gcc_assert (!TREE_USED (fn)); return fn; } -- 2.30.2