Commit a2182c9c by Than McIntosh Committed by Ian Lance Taylor

compiler: add containing Bfunction to conditional_expression

    
    Add containing Bfunction to Backend::conditional_expression
    method signature, since the back end might need to create a
    temporary when generating IR for this construct.
    
    Reviewed-on: https://go-review.googlesource.com/35056

From-SVN: r244330
parent 1f258a55
2017-01-11 Than McIntosh <thanm@google.com>
* go-gcc.cc (conditional_expression): Add Bfunction parameter.
2017-01-01 Jakub Jelinek <jakub@redhat.com> 2017-01-01 Jakub Jelinek <jakub@redhat.com>
Update copyright years. Update copyright years.
......
...@@ -325,8 +325,8 @@ class Gcc_backend : public Backend ...@@ -325,8 +325,8 @@ class Gcc_backend : public Backend
compound_expression(Bstatement*, Bexpression*, Location); compound_expression(Bstatement*, Bexpression*, Location);
Bexpression* Bexpression*
conditional_expression(Btype*, Bexpression*, Bexpression*, Bexpression*, conditional_expression(Bfunction*, Btype*, Bexpression*, Bexpression*,
Location); Bexpression*, Location);
Bexpression* Bexpression*
unary_expression(Operator, Bexpression*, Location); unary_expression(Operator, Bexpression*, Location);
...@@ -1546,7 +1546,8 @@ Gcc_backend::compound_expression(Bstatement* bstat, Bexpression* bexpr, ...@@ -1546,7 +1546,8 @@ Gcc_backend::compound_expression(Bstatement* bstat, Bexpression* bexpr,
// ELSE_EXPR otherwise. // ELSE_EXPR otherwise.
Bexpression* Bexpression*
Gcc_backend::conditional_expression(Btype* btype, Bexpression* condition, Gcc_backend::conditional_expression(Bfunction*, Btype* btype,
Bexpression* condition,
Bexpression* then_expr, Bexpression* then_expr,
Bexpression* else_expr, Location location) Bexpression* else_expr, Location location)
{ {
......
6be46149636c3533389e62c6dc76f0a7ff461080 153f7b68c0c4d3cf3da0becf82eb1a3eb8b47d6e
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -324,12 +324,12 @@ class Backend ...@@ -324,12 +324,12 @@ class Backend
compound_expression(Bstatement* bstat, Bexpression* bexpr, Location) = 0; compound_expression(Bstatement* bstat, Bexpression* bexpr, Location) = 0;
// Return an expression that executes THEN_EXPR if CONDITION is true, or // Return an expression that executes THEN_EXPR if CONDITION is true, or
// ELSE_EXPR otherwise and returns the result as type BTYPE. ELSE_EXPR // ELSE_EXPR otherwise and returns the result as type BTYPE, within the
// may be NULL. BTYPE may be NULL. // specified function FUNCTION. ELSE_EXPR may be NULL. BTYPE may be NULL.
virtual Bexpression* virtual Bexpression*
conditional_expression(Btype* btype, Bexpression* condition, conditional_expression(Bfunction* function, Btype* btype,
Bexpression* then_expr, Bexpression* else_expr, Bexpression* condition, Bexpression* then_expr,
Location) = 0; Bexpression* else_expr, Location) = 0;
// Return an expression for the unary operation OP EXPR. // Return an expression for the unary operation OP EXPR.
// Supported values of OP are (from operators.h): // Supported values of OP are (from operators.h):
......
...@@ -4390,7 +4390,9 @@ Unary_expression::do_get_backend(Translate_context* context) ...@@ -4390,7 +4390,9 @@ Unary_expression::do_get_backend(Translate_context* context)
Bexpression* crash = Bexpression* crash =
gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE, gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
loc)->get_backend(context); loc)->get_backend(context);
bexpr = gogo->backend()->conditional_expression(btype, compare, Bfunction* bfn = context->function()->func_value()->get_decl();
bexpr = gogo->backend()->conditional_expression(bfn, btype,
compare,
crash, bexpr, crash, bexpr,
loc); loc);
...@@ -5992,6 +5994,7 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -5992,6 +5994,7 @@ Binary_expression::do_get_backend(Translate_context* context)
Bexpression* zero_expr = Bexpression* zero_expr =
gogo->backend()->integer_constant_expression(left_btype, zero); gogo->backend()->integer_constant_expression(left_btype, zero);
overflow = zero_expr; overflow = zero_expr;
Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->op_ == OPERATOR_RSHIFT if (this->op_ == OPERATOR_RSHIFT
&& !left_type->integer_type()->is_unsigned()) && !left_type->integer_type()->is_unsigned())
{ {
...@@ -6000,11 +6003,12 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -6000,11 +6003,12 @@ Binary_expression::do_get_backend(Translate_context* context)
zero_expr, loc); zero_expr, loc);
Bexpression* neg_one_expr = Bexpression* neg_one_expr =
gogo->backend()->integer_constant_expression(left_btype, neg_one); gogo->backend()->integer_constant_expression(left_btype, neg_one);
overflow = gogo->backend()->conditional_expression(btype, neg_expr, overflow = gogo->backend()->conditional_expression(bfn,
btype, neg_expr,
neg_one_expr, neg_one_expr,
zero_expr, loc); zero_expr, loc);
} }
ret = gogo->backend()->conditional_expression(btype, compare, ret, ret = gogo->backend()->conditional_expression(bfn, btype, compare, ret,
overflow, loc); overflow, loc);
mpz_clear(bitsval); mpz_clear(bitsval);
} }
...@@ -6027,7 +6031,9 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -6027,7 +6031,9 @@ Binary_expression::do_get_backend(Translate_context* context)
loc)->get_backend(context); loc)->get_backend(context);
// right == 0 ? (__go_runtime_error(...), 0) : ret // right == 0 ? (__go_runtime_error(...), 0) : ret
ret = gogo->backend()->conditional_expression(btype, check, crash, Bfunction* bfn = context->function()->func_value()->get_decl();
ret = gogo->backend()->conditional_expression(bfn, btype,
check, crash,
ret, loc); ret, loc);
} }
...@@ -6047,6 +6053,7 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -6047,6 +6053,7 @@ Binary_expression::do_get_backend(Translate_context* context)
gogo->backend()->integer_constant_expression(btype, zero); gogo->backend()->integer_constant_expression(btype, zero);
Bexpression* one_expr = Bexpression* one_expr =
gogo->backend()->integer_constant_expression(btype, one); gogo->backend()->integer_constant_expression(btype, one);
Bfunction* bfn = context->function()->func_value()->get_decl();
if (type->integer_type()->is_unsigned()) if (type->integer_type()->is_unsigned())
{ {
...@@ -6058,12 +6065,12 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -6058,12 +6065,12 @@ Binary_expression::do_get_backend(Translate_context* context)
left, right, loc); left, right, loc);
if (this->op_ == OPERATOR_DIV) if (this->op_ == OPERATOR_DIV)
overflow = overflow =
gogo->backend()->conditional_expression(btype, cmp, gogo->backend()->conditional_expression(bfn, btype, cmp,
one_expr, zero_expr, one_expr, zero_expr,
loc); loc);
else else
overflow = overflow =
gogo->backend()->conditional_expression(btype, cmp, gogo->backend()->conditional_expression(bfn, btype, cmp,
zero_expr, left, zero_expr, left,
loc); loc);
} }
...@@ -6083,7 +6090,8 @@ Binary_expression::do_get_backend(Translate_context* context) ...@@ -6083,7 +6090,8 @@ Binary_expression::do_get_backend(Translate_context* context)
overflow = gogo->backend()->convert_expression(btype, overflow, loc); overflow = gogo->backend()->convert_expression(btype, overflow, loc);
// right == -1 ? - left : ret // right == -1 ? - left : ret
ret = gogo->backend()->conditional_expression(btype, check, overflow, ret = gogo->backend()->conditional_expression(bfn, btype,
check, overflow,
ret, loc); ret, loc);
} }
} }
...@@ -10923,12 +10931,13 @@ Array_index_expression::do_get_backend(Translate_context* context) ...@@ -10923,12 +10931,13 @@ Array_index_expression::do_get_backend(Translate_context* context)
bad_index = gogo->backend()->binary_expression(OPERATOR_OROR, start_too_large, bad_index = gogo->backend()->binary_expression(OPERATOR_OROR, start_too_large,
bad_index, loc); bad_index, loc);
Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->end_ == NULL) if (this->end_ == NULL)
{ {
// Simple array indexing. This has to return an l-value, so // Simple array indexing. This has to return an l-value, so
// wrap the index check into START. // wrap the index check into START.
start = start =
gogo->backend()->conditional_expression(int_btype, bad_index, gogo->backend()->conditional_expression(bfn, int_btype, bad_index,
crash, start, loc); crash, start, loc);
Bexpression* ret; Bexpression* ret;
...@@ -11017,7 +11026,7 @@ Array_index_expression::do_get_backend(Translate_context* context) ...@@ -11017,7 +11026,7 @@ Array_index_expression::do_get_backend(Translate_context* context)
Bexpression* ctor = Bexpression* ctor =
gogo->backend()->constructor_expression(struct_btype, init, loc); gogo->backend()->constructor_expression(struct_btype, init, loc);
return gogo->backend()->conditional_expression(struct_btype, bad_index, return gogo->backend()->conditional_expression(bfn, struct_btype, bad_index,
crash, ctor, loc); crash, ctor, loc);
} }
...@@ -11231,6 +11240,7 @@ String_index_expression::do_get_backend(Translate_context* context) ...@@ -11231,6 +11240,7 @@ String_index_expression::do_get_backend(Translate_context* context)
} }
Expression* start = Expression::make_cast(int_type, this->start_, loc); Expression* start = Expression::make_cast(int_type, this->start_, loc);
Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->end_ == NULL) if (this->end_ == NULL)
{ {
...@@ -11253,8 +11263,9 @@ String_index_expression::do_get_backend(Translate_context* context) ...@@ -11253,8 +11263,9 @@ String_index_expression::do_get_backend(Translate_context* context)
Btype* byte_btype = bytes->type()->points_to()->get_backend(gogo); Btype* byte_btype = bytes->type()->points_to()->get_backend(gogo);
Bexpression* index_error = bad_index->get_backend(context); Bexpression* index_error = bad_index->get_backend(context);
return gogo->backend()->conditional_expression(byte_btype, index_error, return gogo->backend()->conditional_expression(bfn, byte_btype,
crash, index, loc); index_error, crash,
index, loc);
} }
Expression* end = NULL; Expression* end = NULL;
...@@ -11274,7 +11285,7 @@ String_index_expression::do_get_backend(Translate_context* context) ...@@ -11274,7 +11285,7 @@ String_index_expression::do_get_backend(Translate_context* context)
Btype* str_btype = strslice->type()->get_backend(gogo); Btype* str_btype = strslice->type()->get_backend(gogo);
Bexpression* index_error = bad_index->get_backend(context); Bexpression* index_error = bad_index->get_backend(context);
return gogo->backend()->conditional_expression(str_btype, index_error, return gogo->backend()->conditional_expression(bfn, str_btype, index_error,
crash, bstrslice, loc); crash, bstrslice, loc);
} }
...@@ -11967,8 +11978,10 @@ Interface_field_reference_expression::do_get_backend(Translate_context* context) ...@@ -11967,8 +11978,10 @@ Interface_field_reference_expression::do_get_backend(Translate_context* context)
Bexpression* bcrash = gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE, Bexpression* bcrash = gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
loc)->get_backend(context); loc)->get_backend(context);
Bfunction* bfn = context->function()->func_value()->get_decl();
Bexpression* bcond = Bexpression* bcond =
gogo->backend()->conditional_expression(NULL, bnil_check, bcrash, NULL, loc); gogo->backend()->conditional_expression(bfn, NULL,
bnil_check, bcrash, NULL, loc);
Bfunction* bfunction = context->function()->func_value()->get_decl(); Bfunction* bfunction = context->function()->func_value()->get_decl();
Bstatement* cond_statement = Bstatement* cond_statement =
gogo->backend()->expression_statement(bfunction, bcond); gogo->backend()->expression_statement(bfunction, bcond);
...@@ -15414,7 +15427,8 @@ Conditional_expression::do_get_backend(Translate_context* context) ...@@ -15414,7 +15427,8 @@ Conditional_expression::do_get_backend(Translate_context* context)
Bexpression* cond = this->cond_->get_backend(context); Bexpression* cond = this->cond_->get_backend(context);
Bexpression* then = this->then_->get_backend(context); Bexpression* then = this->then_->get_backend(context);
Bexpression* belse = this->else_->get_backend(context); Bexpression* belse = this->else_->get_backend(context);
return gogo->backend()->conditional_expression(result_btype, cond, then, Bfunction* bfn = context->function()->func_value()->get_decl();
return gogo->backend()->conditional_expression(bfn, result_btype, cond, then,
belse, this->location()); belse, this->location());
} }
......
...@@ -5718,7 +5718,8 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function, ...@@ -5718,7 +5718,8 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
Expression* ref = Expression* ref =
Expression::make_temporary_reference(this->defer_stack_, end_loc); Expression::make_temporary_reference(this->defer_stack_, end_loc);
Bexpression* bref = ref->get_backend(&context); Bexpression* bref = ref->get_backend(&context);
ret = gogo->backend()->conditional_expression(NULL, bref, ret, NULL, ret = gogo->backend()->conditional_expression(this->fndecl_,
NULL, bref, ret, NULL,
end_loc); end_loc);
stmts.push_back(gogo->backend()->expression_statement(this->fndecl_, ret)); stmts.push_back(gogo->backend()->expression_statement(this->fndecl_, ret));
} }
......
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