aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2017-01-11 18:15:16 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-01-11 18:15:16 +0000
commita2182c9cc2a1d887457e38d13e63598f85443020 (patch)
tree01781f4b52d85c765576949475a9459eba3e295c
parent1f258a55a9df39ecef35d0049c3bf703d6cdbe53 (diff)
downloadgcc-a2182c9cc2a1d887457e38d13e63598f85443020.zip
gcc-a2182c9cc2a1d887457e38d13e63598f85443020.tar.gz
gcc-a2182c9cc2a1d887457e38d13e63598f85443020.tar.bz2
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
-rw-r--r--gcc/go/ChangeLog4
-rw-r--r--gcc/go/go-gcc.cc7
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/backend.h10
-rw-r--r--gcc/go/gofrontend/expressions.cc42
-rw-r--r--gcc/go/gofrontend/gogo.cc3
6 files changed, 44 insertions, 24 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog
index 381e00e..8e37e8b 100644
--- a/gcc/go/ChangeLog
+++ b/gcc/go/ChangeLog
@@ -1,3 +1,7 @@
+2017-01-11 Than McIntosh <thanm@google.com>
+
+ * go-gcc.cc (conditional_expression): Add Bfunction parameter.
+
2017-01-01 Jakub Jelinek <jakub@redhat.com>
Update copyright years.
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 58312e4..ed6fc2c 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -325,8 +325,8 @@ class Gcc_backend : public Backend
compound_expression(Bstatement*, Bexpression*, Location);
Bexpression*
- conditional_expression(Btype*, Bexpression*, Bexpression*, Bexpression*,
- Location);
+ conditional_expression(Bfunction*, Btype*, Bexpression*, Bexpression*,
+ Bexpression*, Location);
Bexpression*
unary_expression(Operator, Bexpression*, Location);
@@ -1546,7 +1546,8 @@ Gcc_backend::compound_expression(Bstatement* bstat, Bexpression* bexpr,
// ELSE_EXPR otherwise.
Bexpression*
-Gcc_backend::conditional_expression(Btype* btype, Bexpression* condition,
+Gcc_backend::conditional_expression(Bfunction*, Btype* btype,
+ Bexpression* condition,
Bexpression* then_expr,
Bexpression* else_expr, Location location)
{
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 457bba8..443de8b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6be46149636c3533389e62c6dc76f0a7ff461080
+153f7b68c0c4d3cf3da0becf82eb1a3eb8b47d6e
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h
index cad659a..93835d9 100644
--- a/gcc/go/gofrontend/backend.h
+++ b/gcc/go/gofrontend/backend.h
@@ -324,12 +324,12 @@ class Backend
compound_expression(Bstatement* bstat, Bexpression* bexpr, Location) = 0;
// Return an expression that executes THEN_EXPR if CONDITION is true, or
- // ELSE_EXPR otherwise and returns the result as type BTYPE. ELSE_EXPR
- // may be NULL. BTYPE may be NULL.
+ // ELSE_EXPR otherwise and returns the result as type BTYPE, within the
+ // specified function FUNCTION. ELSE_EXPR may be NULL. BTYPE may be NULL.
virtual Bexpression*
- conditional_expression(Btype* btype, Bexpression* condition,
- Bexpression* then_expr, Bexpression* else_expr,
- Location) = 0;
+ conditional_expression(Bfunction* function, Btype* btype,
+ Bexpression* condition, Bexpression* then_expr,
+ Bexpression* else_expr, Location) = 0;
// Return an expression for the unary operation OP EXPR.
// Supported values of OP are (from operators.h):
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 473a778..fe4d07b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -4390,7 +4390,9 @@ Unary_expression::do_get_backend(Translate_context* context)
Bexpression* crash =
gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
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,
loc);
@@ -5992,6 +5994,7 @@ Binary_expression::do_get_backend(Translate_context* context)
Bexpression* zero_expr =
gogo->backend()->integer_constant_expression(left_btype, zero);
overflow = zero_expr;
+ Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->op_ == OPERATOR_RSHIFT
&& !left_type->integer_type()->is_unsigned())
{
@@ -6000,11 +6003,12 @@ Binary_expression::do_get_backend(Translate_context* context)
zero_expr, loc);
Bexpression* neg_one_expr =
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,
zero_expr, loc);
}
- ret = gogo->backend()->conditional_expression(btype, compare, ret,
+ ret = gogo->backend()->conditional_expression(bfn, btype, compare, ret,
overflow, loc);
mpz_clear(bitsval);
}
@@ -6027,7 +6031,9 @@ Binary_expression::do_get_backend(Translate_context* context)
loc)->get_backend(context);
// 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);
}
@@ -6047,6 +6053,7 @@ Binary_expression::do_get_backend(Translate_context* context)
gogo->backend()->integer_constant_expression(btype, zero);
Bexpression* one_expr =
gogo->backend()->integer_constant_expression(btype, one);
+ Bfunction* bfn = context->function()->func_value()->get_decl();
if (type->integer_type()->is_unsigned())
{
@@ -6058,12 +6065,12 @@ Binary_expression::do_get_backend(Translate_context* context)
left, right, loc);
if (this->op_ == OPERATOR_DIV)
overflow =
- gogo->backend()->conditional_expression(btype, cmp,
+ gogo->backend()->conditional_expression(bfn, btype, cmp,
one_expr, zero_expr,
loc);
else
overflow =
- gogo->backend()->conditional_expression(btype, cmp,
+ gogo->backend()->conditional_expression(bfn, btype, cmp,
zero_expr, left,
loc);
}
@@ -6083,7 +6090,8 @@ Binary_expression::do_get_backend(Translate_context* context)
overflow = gogo->backend()->convert_expression(btype, overflow, loc);
// right == -1 ? - left : ret
- ret = gogo->backend()->conditional_expression(btype, check, overflow,
+ ret = gogo->backend()->conditional_expression(bfn, btype,
+ check, overflow,
ret, loc);
}
}
@@ -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, loc);
+ Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->end_ == NULL)
{
// Simple array indexing. This has to return an l-value, so
// wrap the index check into START.
start =
- gogo->backend()->conditional_expression(int_btype, bad_index,
+ gogo->backend()->conditional_expression(bfn, int_btype, bad_index,
crash, start, loc);
Bexpression* ret;
@@ -11017,7 +11026,7 @@ Array_index_expression::do_get_backend(Translate_context* context)
Bexpression* ctor =
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);
}
@@ -11231,6 +11240,7 @@ String_index_expression::do_get_backend(Translate_context* context)
}
Expression* start = Expression::make_cast(int_type, this->start_, loc);
+ Bfunction* bfn = context->function()->func_value()->get_decl();
if (this->end_ == NULL)
{
@@ -11253,8 +11263,9 @@ String_index_expression::do_get_backend(Translate_context* context)
Btype* byte_btype = bytes->type()->points_to()->get_backend(gogo);
Bexpression* index_error = bad_index->get_backend(context);
- return gogo->backend()->conditional_expression(byte_btype, index_error,
- crash, index, loc);
+ return gogo->backend()->conditional_expression(bfn, byte_btype,
+ index_error, crash,
+ index, loc);
}
Expression* end = NULL;
@@ -11274,7 +11285,7 @@ String_index_expression::do_get_backend(Translate_context* context)
Btype* str_btype = strslice->type()->get_backend(gogo);
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);
}
@@ -11967,8 +11978,10 @@ Interface_field_reference_expression::do_get_backend(Translate_context* context)
Bexpression* bcrash = gogo->runtime_error(RUNTIME_ERROR_NIL_DEREFERENCE,
loc)->get_backend(context);
+ Bfunction* bfn = context->function()->func_value()->get_decl();
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();
Bstatement* cond_statement =
gogo->backend()->expression_statement(bfunction, bcond);
@@ -15414,7 +15427,8 @@ Conditional_expression::do_get_backend(Translate_context* context)
Bexpression* cond = this->cond_->get_backend(context);
Bexpression* then = this->then_->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());
}
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index ffe51b3..34346a7 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -5718,7 +5718,8 @@ Function::build_defer_wrapper(Gogo* gogo, Named_object* named_function,
Expression* ref =
Expression::make_temporary_reference(this->defer_stack_, end_loc);
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);
stmts.push_back(gogo->backend()->expression_statement(this->fndecl_, ret));
}