Commit bedcedc1 by Ian Lance Taylor

compiler: Fix handling of indirection of circular types.

From-SVN: r184686
parent ce842ad6
...@@ -4705,29 +4705,33 @@ Unary_expression::do_get_tree(Translate_context* context) ...@@ -4705,29 +4705,33 @@ Unary_expression::do_get_tree(Translate_context* context)
// need to check for nil. We don't bother to check for small // need to check for nil. We don't bother to check for small
// structs because we expect the system to crash on a nil // structs because we expect the system to crash on a nil
// pointer dereference. // pointer dereference.
HOST_WIDE_INT s = int_size_in_bytes(TREE_TYPE(TREE_TYPE(expr))); tree target_type_tree = TREE_TYPE(TREE_TYPE(expr));
if (s == -1 || s >= 4096) if (!VOID_TYPE_P(target_type_tree))
{ {
if (!DECL_P(expr)) HOST_WIDE_INT s = int_size_in_bytes(target_type_tree);
expr = save_expr(expr); if (s == -1 || s >= 4096)
tree compare = fold_build2_loc(loc.gcc_location(), EQ_EXPR, {
boolean_type_node, if (!DECL_P(expr))
expr, expr = save_expr(expr);
fold_convert(TREE_TYPE(expr), tree compare = fold_build2_loc(loc.gcc_location(), EQ_EXPR,
null_pointer_node)); boolean_type_node,
tree crash = Gogo::runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE, expr,
loc); fold_convert(TREE_TYPE(expr),
expr = fold_build2_loc(loc.gcc_location(), COMPOUND_EXPR, null_pointer_node));
TREE_TYPE(expr), build3(COND_EXPR, tree crash = Gogo::runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
void_type_node, loc);
compare, crash, expr = fold_build2_loc(loc.gcc_location(), COMPOUND_EXPR,
NULL_TREE), TREE_TYPE(expr), build3(COND_EXPR,
expr); void_type_node,
compare, crash,
NULL_TREE),
expr);
}
} }
// If the type of EXPR is a recursive pointer type, then we // If the type of EXPR is a recursive pointer type, then we
// need to insert a cast before indirecting. // need to insert a cast before indirecting.
if (TREE_TYPE(TREE_TYPE(expr)) == ptr_type_node) if (VOID_TYPE_P(target_type_tree))
{ {
Type* pt = this->expr_->type()->points_to(); Type* pt = this->expr_->type()->points_to();
tree ind = type_to_tree(pt->get_backend(context->gogo())); tree ind = type_to_tree(pt->get_backend(context->gogo()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment