aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Manghane <cmang@google.com>2014-05-06 13:50:01 +0000
committerIan Lance Taylor <iant@google.com>2014-05-06 13:50:01 +0000
commit4153daccdae7ad4153b59b93e8751bcd24309d8e (patch)
treecbfe6afa638ce0b18b2e51c55acff495e07956d6
parentd0a340798d437198641a6fa1dc0e258e2356842a (diff)
compiler: Store flags for division checks in Gogo object instead of using global variables.
* go-c.h (go_create_gogo): Update declaration to add check_divide_zero and check_divide_overflow parameters. * go-lang.c (go_langhook_init): Pass new arguments to go_create_gogo. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@210109 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/ChangeLog7
-rw-r--r--gcc/go/go-c.h3
-rw-r--r--gcc/go/go-lang.c3
-rw-r--r--gcc/go/gofrontend/expressions.cc12
-rw-r--r--gcc/go/gofrontend/go.cc7
-rw-r--r--gcc/go/gofrontend/gogo.h28
6 files changed, 49 insertions, 11 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog
index 8fe468f9b3d..b4267ab9873 100644
--- a/gcc/go/ChangeLog
+++ b/gcc/go/ChangeLog
@@ -1,3 +1,10 @@
+2014-05-06 Chris Manghane <cmang@google.com>
+
+ * go-c.h (go_create_gogo): Update declaration to add
+ check_divide_zero and check_divide_overflow parameters.
+ * go-lang.c (go_langhook_init): Pass new arguments to
+ go_create_gogo.
+
2014-05-05 Chris Manghane <cmang@google.com>
* go-gcc.cc (Gcc_backend::implicit_variable): Rename from
diff --git a/gcc/go/go-c.h b/gcc/go/go-c.h
index cb10f2b7be7..5f5ac0da9bc 100644
--- a/gcc/go/go-c.h
+++ b/gcc/go/go-c.h
@@ -34,7 +34,8 @@ extern void go_add_search_path (const char*);
extern void go_create_gogo (int int_type_size, int pointer_size,
const char* pkgpath, const char *prefix,
- const char *relative_import_path);
+ const char *relative_import_path,
+ bool check_divide_zero, bool check_divide_overflow);
extern void go_parse_input_files (const char**, unsigned int,
bool only_check_syntax,
diff --git a/gcc/go/go-lang.c b/gcc/go/go-lang.c
index 3599aa85e54..f6e865e08cf 100644
--- a/gcc/go/go-lang.c
+++ b/gcc/go/go-lang.c
@@ -104,7 +104,8 @@ go_langhook_init (void)
build_common_builtin_nodes (because it calls, indirectly,
go_type_for_size). */
go_create_gogo (INT_TYPE_SIZE, POINTER_SIZE, go_pkgpath, go_prefix,
- go_relative_import_path);
+ go_relative_import_path, go_check_divide_zero,
+ go_check_divide_overflow);
build_common_builtin_nodes ();
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 9381764e143..df3103b0d1d 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -5432,7 +5432,7 @@ Binary_expression::lower_compare_to_memcmp(Gogo*, Statement_inserter* inserter)
}
Expression*
-Binary_expression::do_flatten(Gogo*, Named_object*,
+Binary_expression::do_flatten(Gogo* gogo, Named_object*,
Statement_inserter* inserter)
{
Location loc = this->location();
@@ -5462,11 +5462,9 @@ Binary_expression::do_flatten(Gogo*, Named_object*,
left_type->integer_type() != NULL)
|| this->op_ == OPERATOR_MOD);
- // FIXME: go_check_divide_zero and go_check_divide_overflow are globals
- // defined in gcc/go/lang.opt. These should be defined in go_create_gogo
- // and accessed from the Gogo* passed to do_flatten.
if (is_shift_op
- || (is_idiv_op && (go_check_divide_zero || go_check_divide_overflow)))
+ || (is_idiv_op
+ && (gogo->check_divide_by_zero() || gogo->check_divide_overflow())))
{
if (!this->left_->is_variable())
{
@@ -6046,7 +6044,7 @@ Binary_expression::do_get_tree(Translate_context* context)
// Add checks for division by zero and division overflow as needed.
if (is_idiv_op)
{
- if (go_check_divide_zero)
+ if (gogo->check_divide_by_zero())
{
// right == 0
Bexpression* zero_expr =
@@ -6065,7 +6063,7 @@ Binary_expression::do_get_tree(Translate_context* context)
crash_expr, ret, loc);
}
- if (go_check_divide_overflow)
+ if (gogo->check_divide_overflow())
{
// right == -1
// FIXME: It would be nice to say that this test is expected
diff --git a/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc
index d2331f3e0ae..222ea90ae01 100644
--- a/gcc/go/gofrontend/go.cc
+++ b/gcc/go/gofrontend/go.cc
@@ -21,7 +21,8 @@ static Gogo* gogo;
GO_EXTERN_C
void
go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath,
- const char *prefix, const char *relative_import_path)
+ const char *prefix, const char *relative_import_path,
+ bool check_divide_by_zero, bool check_divide_overflow)
{
go_assert(::gogo == NULL);
Linemap* linemap = go_get_linemap();
@@ -34,6 +35,10 @@ go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath,
if (relative_import_path != NULL)
::gogo->set_relative_import_path(relative_import_path);
+ if (check_divide_by_zero)
+ ::gogo->set_check_divide_by_zero(check_divide_by_zero);
+ if (check_divide_overflow)
+ ::gogo->set_check_divide_overflow(check_divide_overflow);
}
// Parse the input files.
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 37cbbdf4411..f125201643f 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -215,7 +215,27 @@ class Gogo
// Set the relative import path from a command line option.
void
set_relative_import_path(const std::string& s)
- {this->relative_import_path_ = s; }
+ { this->relative_import_path_ = s; }
+
+ // Return whether to check for division by zero in binary operations.
+ bool
+ check_divide_by_zero() const
+ { return this->check_divide_by_zero_; }
+
+ // Set the option to check division by zero from a command line option.
+ void
+ set_check_divide_by_zero(bool b)
+ { this->check_divide_by_zero_ = b; }
+
+ // Return whether to check for division overflow in binary operations.
+ bool
+ check_divide_overflow() const
+ { return this->check_divide_overflow_; }
+
+ // Set the option to check division overflow from a command line option.
+ void
+ set_check_divide_overflow(bool b)
+ { this->check_divide_overflow_ = b; }
// Return the priority to use for the package we are compiling.
// This is two more than the largest priority of any package we
@@ -716,6 +736,12 @@ class Gogo
// The relative import path, from the -fgo-relative-import-path
// option.
std::string relative_import_path_;
+ // Whether or not to check for division by zero, from the
+ // -fgo-check-divide-zero option.
+ bool check_divide_by_zero_;
+ // Whether or not to check for division overflow, from the
+ // -fgo-check-divide-overflow option.
+ bool check_divide_overflow_;
// A list of types to verify.
std::vector<Type*> verify_types_;
// A list of interface types defined while parsing.