compiler: Store flags for division checks in Gogo object instead of using global...
authorChris Manghane <cmang@google.com>
Tue, 6 May 2014 13:50:01 +0000 (13:50 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 6 May 2014 13:50:01 +0000 (13:50 +0000)
* 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

gcc/go/ChangeLog
gcc/go/go-c.h
gcc/go/go-lang.c
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/go.cc
gcc/go/gofrontend/gogo.h

index 8fe468f..b4267ab 100644 (file)
@@ -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
index cb10f2b..5f5ac0d 100644 (file)
@@ -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,
index 3599aa8..f6e865e 100644 (file)
@@ -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 ();
 
index 9381764..df3103b 100644 (file)
@@ -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
index d2331f3..222ea90 100644 (file)
@@ -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.
index 37cbbdf..f125201 100644 (file)
@@ -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.