Skip to content

Commit

Permalink
rust-unreachable: Add specific behavior for rust_unreachable
Browse files Browse the repository at this point in the history
As discussed during the community call, rust_unreachable() should
always trigger an internal compiler error and should not offer
the behavior of __builtin_unreachable when asserts are disabled, unlike
gcc_unreachable().

gcc/rust/ChangeLog:

	* rust-system.h (rust_unreachable): Change definition to fancy_abort
	* ast/rust-ast-collector.cc (TokenCollector::visit): Use rust_unreachable
	instead of gcc_unreachable.
	(get_delimiters): Likewise.
	* ast/rust-ast-dump.h: Likewise.
	* ast/rust-ast-formatting.cc (get_string_in_delims): Likewise.
	(get_mode_dump_desc): Likewise.
	* ast/rust-ast.cc (Visibility::as_string): Likewise.
	(UseTreeGlob::as_string): Likewise.
	* ast/rust-ast.h: Likewise.
	* ast/rust-macro.h: Likewise.
	* ast/rust-path.h: Likewise.
	* backend/rust-compile-expr.cc (sort_tuple_patterns): Likewise.
	(CompileExpr::visit): Likewise.
	(CompileExpr::generate_closure_fntype): Likewise.
	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): Likewise.
	* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise.
	(CompilePatternLet::visit): Likewise.
	* backend/rust-constexpr.cc (base_field_constructor_elt): Likewise.
	(eval_array_reference): Likewise.
	(label_matches): Likewise.
	(eval_store_expression): Likewise.
	(eval_call_expression): Likewise.
	(build_data_member_initialization): Likewise.
	(array_index_cmp): Likewise.
	(get_array_or_vector_nelts): Likewise.
	(eval_bit_field_ref): Likewise.
	(eval_loop_expr): Likewise.
	(potential_constant_expression_1): Likewise.
	* backend/rust-mangle.cc (v0_simple_type_prefix): Likewise.
	(v0_type_prefix): Likewise.
	(v0_mangle_item): Likewise.
	(Mangler::mangle_item): Likewise.
	* backend/rust-tree.cc (convert_to_void): Likewise.
	(type_memfn_quals): Likewise.
	(rs_tree_equal): Likewise.
	(fold_offsetof): Likewise.
	(fold_builtin_source_location): Likewise.
	(lvalue_error): Likewise.
	* backend/rust-tree.h (struct named_decl_hash): Likewise.
	(struct named_label_hash): Likewise.
	* checks/errors/privacy/rust-visibility-resolver.cc
	(VisibilityResolver::resolve_visibility): Likewise.
	(VisibilityResolver::visit): Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Likewise.
	* checks/errors/rust-feature.cc (Feature::create): Likewise.
	* expand/rust-expand-visitor.cc (get_traits_to_derive): Likewise.
	(derive_item): Likewise.
	(expand_item_attribute): Likewise.
	(expand_stmt_attribute): Likewise.
	* expand/rust-macro-expand.cc (MacroExpander::match_matcher): Likewise.
	(MacroExpander::match_repetition): Likewise.
	(transcribe_context): Likewise.
	(MacroExpander::import_proc_macros): Likewise.
	(MacroExpander::parse_proc_macro_output): Likewise.
	* expand/rust-macro-expand.h: Likewise.
	* expand/rust-macro-invoc-lexer.h: Likewise.
	* expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise.
	* expand/rust-proc-macro-invoc-lexer.h: Likewise.
	* expand/rust-proc-macro.cc (load_macros): Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise.
	(ASTLoweringBase::lower_literal): Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise.
	* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/tree/rust-hir.cc (get_string_in_delims): Likewise.
	(Visibility::as_string): Likewise.
	(UseTreeGlob::as_string): Likewise.
	(CompoundAssignmentExpr::as_string): Likewise.
	(ArithmeticOrLogicalExpr::as_string): Likewise.
	* lex/rust-lex.cc (Lexer::parse_byte_string): Likewise.
	(Lexer::parse_string): Likewise.
	* lex/rust-token.cc (RS_TOKEN): Likewise.
	* parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise.
	(Parser::parse_path_ident_segment): Likewise.
	(Parser::parse_attr_input): Likewise.
	(Parser::parse_inherent_impl_item): Likewise.
	(Parser::parse_trait_impl_item): Likewise.
	(Parser::parse_type_path_segment): Likewise.
	(Parser::parse_reference_type): Likewise.
	(get_lbp_for_comparison_expr): Likewise.
	* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise.
	* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
	* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise.
	* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
	(ResolveTypeToCanonicalPath::visit): Likewise.
	(ResolveGenericArgs::resolve_disambiguated_generic): Likewise.
	* rust-gcc.cc (operator_to_tree_code): Likewise.
	(fetch_overflow_builtins): Likewise.
	(Gcc_backend::non_zero_size_type): Likewise.
	(Gcc_backend::convert_tree): Likewise.
	* rust-lang.cc (grs_langhook_type_for_mode): Likewise.
	(grs_langhook_global_bindings_p): Likewise.
	(grs_langhook_pushdecl): Likewise.
	(grs_langhook_getdecls): Likewise.
	(convert): Likewise.
	* typecheck/rust-autoderef.h: Likewise.
	* typecheck/rust-hir-path-probe.cc: Likewise.
	* typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty): Likewise.
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise.
	* typecheck/rust-hir-type-check-expr.cc: Likewise.
	* typecheck/rust-hir-type-check-expr.h: Likewise.
	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise.
	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
	* typecheck/rust-hir-type-check-stmt.h: Likewise.
	* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise.
	* typecheck/rust-substitution-mapper.h: Likewise.
	* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_context_type): Likewise.
	* typecheck/rust-tyty-call.h: Likewise.
	* typecheck/rust-tyty.cc (TypeKindFormat::to_string): Likewise.
	(BaseType::monomorphized_clone): Likewise.
	(VariantDef::variant_type_string): Likewise.
	(ClosureType::handle_substitions): Likewise.
	(IntType::as_string): Likewise.
	(UintType::as_string): Likewise.
	(FloatType::as_string): Likewise.
	* typecheck/rust-unify.cc (UnifyRules::expect_projection): Likewise.
	* util/rust-token-converter.cc (convert): Likewise.
	(from_literal): Likewise.
	(from_group): Likewise.
	(from_tokentree): Likewise.
  • Loading branch information
CohenArthur authored and philberty committed Jul 14, 2023
1 parent a34d667 commit 866512c
Show file tree
Hide file tree
Showing 56 changed files with 230 additions and 220 deletions.
12 changes: 6 additions & 6 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ TokenCollector::visit (Attribute &attrib)
break;
}
default:
gcc_unreachable ();
rust_unreachable ();
}
}
push (Rust::Token::make (RIGHT_SQUARE, UNDEF_LOCATION));
Expand Down Expand Up @@ -668,7 +668,7 @@ TokenCollector::visit (GenericArg &arg)
}
break;
case GenericArg::Kind::Error:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down Expand Up @@ -822,11 +822,11 @@ TokenCollector::visit (Literal &lit, Location locus)
else if (value == "true")
push (Rust::Token::make (TRUE_LITERAL, locus));
else
gcc_unreachable (); // Not a boolean
rust_unreachable (); // Not a boolean
break;
}
case Literal::LitType::ERROR:
gcc_unreachable ();
rust_unreachable ();
break;
}
}
Expand Down Expand Up @@ -1188,7 +1188,7 @@ void
TokenCollector::visit (StructExprStructBase &)
{
// FIXME: Implement this node
gcc_unreachable ();
rust_unreachable ();
}

void
Expand Down Expand Up @@ -2252,7 +2252,7 @@ get_delimiters (DelimType delim)
case CURLY:
return {LEFT_CURLY, RIGHT_CURLY};
default:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Dump
previous = nullptr;
break;
default:
gcc_unreachable ();
rust_unreachable ();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-ast-formatting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ get_string_in_delims (std::string str_input, DelimType delim_type)
default:
return "ERROR-MARK-STRING (delims)";
}
gcc_unreachable ();
rust_unreachable ();
}

std::string
Expand All @@ -64,7 +64,7 @@ get_mode_dump_desc (AttrMode mode)
case INNER:
return "inner attributes";
default:
gcc_unreachable ();
rust_unreachable ();
return "";
}
}
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Visibility::as_string () const
case PUB_IN_PATH:
return std::string ("pub(in ") + in_path.as_string () + std::string (")");
default:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down Expand Up @@ -623,7 +623,7 @@ UseTreeGlob::as_string () const
// some kind of error
return "ERROR-PATH";
}
gcc_unreachable ();
rust_unreachable ();
}

std::string
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ class SingleASTNode : public Visitable
return type == nullptr;
}

gcc_unreachable ();
rust_unreachable ();
return true;
}

Expand All @@ -1913,7 +1913,7 @@ class SingleASTNode : public Visitable
return "Type: " + type->as_string ();
}

gcc_unreachable ();
rust_unreachable ();
return "";
}
};
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,14 @@ class MacroRulesDefinition : public VisItem

/**
* Default function to use as an associated transcriber. This function should
* never be called, hence the gcc_unreachable().
* never be called, hence the rust_unreachable().
* If this function is used, then the macro is not builtin and the compiler
* should make use of the actual rules. If the macro is builtin, then another
* associated transcriber should be used
*/
static Fragment dummy_builtin (Location, MacroInvocData &)
{
gcc_unreachable ();
rust_unreachable ();
return Fragment::create_error ();
}

Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class GenericArg
case Kind::Either:
break;
case Kind::Error:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ class GenericArg
switch (get_kind ())
{
case Kind::Error:
gcc_unreachable ();
rust_unreachable ();
case Kind::Either:
return "Ambiguous: " + path.as_string ();
case Kind::Const:
Expand Down
12 changes: 6 additions & 6 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ sort_tuple_patterns (HIR::MatchExpr &expr)
else /* TuplePatternItemType::RANGED */
{
// FIXME
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down Expand Up @@ -1430,25 +1430,25 @@ CompileExpr::visit (HIR::MatchExpr &expr)
else
{
// FIXME: There are other cases, but it better not be a Tuple
gcc_unreachable ();
rust_unreachable ();
}
}
break;

case HIR::Expr::ExprType::Path: {
// FIXME
gcc_unreachable ();
rust_unreachable ();
}
break;

default:
gcc_unreachable ();
rust_unreachable ();
}
}
else
{
// FIXME: match on other types of expressions not yet implemented.
gcc_unreachable ();
rust_unreachable ();
}

// setup the end label so the cases can exit properly
Expand Down Expand Up @@ -2856,7 +2856,7 @@ CompileExpr::generate_closure_fntype (HIR::ClosureExpr &expr,
else
{
// FIXME error message?
gcc_unreachable ();
rust_unreachable ();
return error_mark_node;
}

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/backend/rust-compile-intrinsic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
break;

default:
gcc_unreachable ();
rust_unreachable ();
break;
}
rust_assert (overflow_builtin != error_mark_node);
Expand Down
8 changes: 4 additions & 4 deletions gcc/rust/backend/rust-compile-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern)
{
case HIR::TupleStructItems::RANGE: {
// TODO
gcc_unreachable ();
rust_unreachable ();
}
break;

Expand Down Expand Up @@ -284,13 +284,13 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
{
case HIR::StructPatternField::ItemType::TUPLE_PAT: {
// TODO
gcc_unreachable ();
rust_unreachable ();
}
break;

case HIR::StructPatternField::ItemType::IDENT_PAT: {
// TODO
gcc_unreachable ();
rust_unreachable ();
}
break;

Expand Down Expand Up @@ -467,7 +467,7 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern)
return;
}
default: {
gcc_unreachable ();
rust_unreachable ();
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions gcc/rust/backend/rust-constexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ base_field_constructor_elt (vec<constructor_elt, va_gc> *v, tree ref)
if (ce->index == field)
return ce;

gcc_unreachable ();
rust_unreachable ();
return NULL;
}

Expand Down Expand Up @@ -1618,7 +1618,7 @@ eval_array_reference (const constexpr_ctx *ctx, tree t, bool lval,
/* We can't do anything with other tree codes, so use
VERIFY_CONSTANT to complain and fail. */
VERIFY_CONSTANT (ary);
gcc_unreachable ();
rust_unreachable ();
}

bool found;
Expand Down Expand Up @@ -1855,7 +1855,7 @@ label_matches (const constexpr_ctx *ctx, tree *jump_target, tree stmt)
break;

default:
gcc_unreachable ();
rust_unreachable ();
}
return false;
}
Expand Down Expand Up @@ -2695,7 +2695,7 @@ eval_store_expression (const constexpr_ctx *ctx, tree t, bool lval,
if (TREE_CODE (probe) == ARRAY_REF)
{
// TODO
gcc_unreachable ();
rust_unreachable ();
// elt = eval_and_check_array_index (ctx, probe, false,
// non_constant_p, overflow_p);
if (*non_constant_p)
Expand Down Expand Up @@ -3372,7 +3372,7 @@ eval_call_expression (const constexpr_ctx *ctx, tree t, bool lval,
{
// return cxx_eval_internal_function (ctx, t, lval,
// non_constant_p, overflow_p);
gcc_unreachable ();
rust_unreachable ();
return error_mark_node;
}

Expand Down Expand Up @@ -3876,7 +3876,7 @@ build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
// goto found;
//
// default:
// gcc_unreachable ();
// rust_unreachable ();
// }
// found:
//
Expand Down Expand Up @@ -4143,7 +4143,7 @@ array_index_cmp (tree key, tree index)
return 0;
}
default:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down Expand Up @@ -4435,7 +4435,7 @@ get_array_or_vector_nelts (const constexpr_ctx *ctx, tree type,
else if (VECTOR_TYPE_P (type))
nelts = size_int (TYPE_VECTOR_SUBPARTS (type));
else
gcc_unreachable ();
rust_unreachable ();

/* For VLAs, the number of elements won't be an integer constant. */
nelts
Expand Down Expand Up @@ -4787,7 +4787,7 @@ eval_bit_field_ref (const constexpr_ctx *ctx, tree t, bool lval,
}
if (fld_seen)
return fold_convert (TREE_TYPE (t), retval);
gcc_unreachable ();
rust_unreachable ();
return error_mark_node;
}

Expand Down Expand Up @@ -4876,7 +4876,7 @@ eval_loop_expr (const constexpr_ctx *ctx, tree t, bool *non_constant_p,
count = -1;
break;
default:
gcc_unreachable ();
rust_unreachable ();
}
auto_vec<tree, 10> save_exprs;
new_ctx.save_exprs = &save_exprs;
Expand Down Expand Up @@ -6433,7 +6433,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,

default:
sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t)));
gcc_unreachable ();
rust_unreachable ();
return false;
}
#undef RECUR
Expand Down
8 changes: 4 additions & 4 deletions gcc/rust/backend/rust-mangle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ v0_simple_type_prefix (const TyTy::BaseType *ty)
return "";
}

gcc_unreachable ();
rust_unreachable ();
}

// Add an underscore-terminated base62 integer to the mangling string.
Expand Down Expand Up @@ -262,7 +262,7 @@ v0_type_prefix (const TyTy::BaseType *ty)
return ty_prefix;

// FIXME: We need to fetch more type prefixes
gcc_unreachable ();
rust_unreachable ();
}

static std::string
Expand Down Expand Up @@ -291,7 +291,7 @@ v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path)
v0_add_identifier (mangled, crate_name);
v0_add_disambiguator (mangled, 62);

gcc_unreachable ();
rust_unreachable ();
}

std::string
Expand All @@ -305,7 +305,7 @@ Mangler::mangle_item (const TyTy::BaseType *ty,
case Mangler::MangleVersion::V0:
return v0_mangle_item (ty, path);
default:
gcc_unreachable ();
rust_unreachable ();
}
}

Expand Down
Loading

0 comments on commit 866512c

Please sign in to comment.