Commit 6122336c by Chris Manghane Committed by Ian Lance Taylor

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.

From-SVN: r210109
parent 3134fb19
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> 2014-05-05 Chris Manghane <cmang@google.com>
* go-gcc.cc (Gcc_backend::implicit_variable): Rename from * go-gcc.cc (Gcc_backend::implicit_variable): Rename from
......
...@@ -34,7 +34,8 @@ extern void go_add_search_path (const char*); ...@@ -34,7 +34,8 @@ extern void go_add_search_path (const char*);
extern void go_create_gogo (int int_type_size, int pointer_size, extern void go_create_gogo (int int_type_size, int pointer_size,
const char* pkgpath, const char *prefix, 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, extern void go_parse_input_files (const char**, unsigned int,
bool only_check_syntax, bool only_check_syntax,
......
...@@ -104,7 +104,8 @@ go_langhook_init (void) ...@@ -104,7 +104,8 @@ go_langhook_init (void)
build_common_builtin_nodes (because it calls, indirectly, build_common_builtin_nodes (because it calls, indirectly,
go_type_for_size). */ go_type_for_size). */
go_create_gogo (INT_TYPE_SIZE, POINTER_SIZE, go_pkgpath, go_prefix, 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 (); build_common_builtin_nodes ();
......
...@@ -5432,7 +5432,7 @@ Binary_expression::lower_compare_to_memcmp(Gogo*, Statement_inserter* inserter) ...@@ -5432,7 +5432,7 @@ Binary_expression::lower_compare_to_memcmp(Gogo*, Statement_inserter* inserter)
} }
Expression* Expression*
Binary_expression::do_flatten(Gogo*, Named_object*, Binary_expression::do_flatten(Gogo* gogo, Named_object*,
Statement_inserter* inserter) Statement_inserter* inserter)
{ {
Location loc = this->location(); Location loc = this->location();
...@@ -5462,11 +5462,9 @@ Binary_expression::do_flatten(Gogo*, Named_object*, ...@@ -5462,11 +5462,9 @@ Binary_expression::do_flatten(Gogo*, Named_object*,
left_type->integer_type() != NULL) left_type->integer_type() != NULL)
|| this->op_ == OPERATOR_MOD); || 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 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()) if (!this->left_->is_variable())
{ {
...@@ -6046,7 +6044,7 @@ Binary_expression::do_get_tree(Translate_context* context) ...@@ -6046,7 +6044,7 @@ Binary_expression::do_get_tree(Translate_context* context)
// Add checks for division by zero and division overflow as needed. // Add checks for division by zero and division overflow as needed.
if (is_idiv_op) if (is_idiv_op)
{ {
if (go_check_divide_zero) if (gogo->check_divide_by_zero())
{ {
// right == 0 // right == 0
Bexpression* zero_expr = Bexpression* zero_expr =
...@@ -6065,7 +6063,7 @@ Binary_expression::do_get_tree(Translate_context* context) ...@@ -6065,7 +6063,7 @@ Binary_expression::do_get_tree(Translate_context* context)
crash_expr, ret, loc); crash_expr, ret, loc);
} }
if (go_check_divide_overflow) if (gogo->check_divide_overflow())
{ {
// right == -1 // right == -1
// FIXME: It would be nice to say that this test is expected // FIXME: It would be nice to say that this test is expected
......
...@@ -21,7 +21,8 @@ static Gogo* gogo; ...@@ -21,7 +21,8 @@ static Gogo* gogo;
GO_EXTERN_C GO_EXTERN_C
void void
go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath, 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); go_assert(::gogo == NULL);
Linemap* linemap = go_get_linemap(); Linemap* linemap = go_get_linemap();
...@@ -34,6 +35,10 @@ go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath, ...@@ -34,6 +35,10 @@ go_create_gogo(int int_type_size, int pointer_size, const char *pkgpath,
if (relative_import_path != NULL) if (relative_import_path != NULL)
::gogo->set_relative_import_path(relative_import_path); ::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. // Parse the input files.
......
...@@ -215,7 +215,27 @@ class Gogo ...@@ -215,7 +215,27 @@ class Gogo
// Set the relative import path from a command line option. // Set the relative import path from a command line option.
void void
set_relative_import_path(const std::string& s) 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. // Return the priority to use for the package we are compiling.
// This is two more than the largest priority of any package we // This is two more than the largest priority of any package we
...@@ -716,6 +736,12 @@ class Gogo ...@@ -716,6 +736,12 @@ class Gogo
// The relative import path, from the -fgo-relative-import-path // The relative import path, from the -fgo-relative-import-path
// option. // option.
std::string relative_import_path_; 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. // A list of types to verify.
std::vector<Type*> verify_types_; std::vector<Type*> verify_types_;
// A list of interface types defined while parsing. // A list of interface types defined while parsing.
......
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