From 5c3f3470f97a047819f593b60db38cf7a34b8187 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 6 May 2014 13:50:01 +0000 Subject: [PATCH] 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: svn+ssh://gcc.gnu.org/svn/gcc/trunk@210109 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/go/ChangeLog | 7 +++++++ gcc/go/go-c.h | 3 ++- gcc/go/go-lang.c | 3 ++- gcc/go/gofrontend/expressions.cc | 12 +++++------- gcc/go/gofrontend/go.cc | 7 ++++++- gcc/go/gofrontend/gogo.h | 28 +++++++++++++++++++++++++++- 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 + + * 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 * 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 verify_types_; // A list of interface types defined while parsing. -- 2.11.4.GIT