diff mbox series

Go patch committed: Nil-checked pointers and indexes can trap

Message ID CAOyqgcWX=z-cOZU27cUgtXYXr7GoO6Rp9D3Dz3sG6WoBX5gJQg@mail.gmail.com
State New
Headers show
Series Go patch committed: Nil-checked pointers and indexes can trap | expand

Commit Message

Ian Lance Taylor Dec. 23, 2020, 10:09 p.m. UTC
The Go frontend was treating indirections through pointers that had
been explicitly checked against nil and slice and string index
expressions as non-trapping memory references.  That is true for
ordinary Go programs, but it isn't true if the programs construct
their own memory addresses.  In particular it isn't true for the kinds
of programs that want to use runtime.SetPanicOnFault.  The effect of
this will be slightly larger binaries, due to additional exception
information, and perhaps slightly less optimization.  Bootstrapped and
ran Go testsuite on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
3224ee488de0b641cd553c25206ed31e9261be47
diff mbox series

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index fbac942ad42..600d9769624 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
-d238487d5c6e0c7f12c38305060fba8b7ec3605f
+8d49adead59b8103f3bfeebd53ee508eda5ee94a
 
 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/expressions.cc b/gcc/go/gofrontend/expressions.cc
index adc1ebb4643..17b4cfd2c19 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -5334,7 +5334,6 @@  Unary_expression::do_get_backend(Translate_context* context)
       {
         go_assert(this->expr_->type()->points_to() != NULL);
 
-        bool known_valid = false;
         Type* ptype = this->expr_->type()->points_to();
         Btype* pbtype = ptype->get_backend(gogo);
         switch (this->requires_nil_check(gogo))
@@ -5375,14 +5374,12 @@  Unary_expression::do_get_backend(Translate_context* context)
                                                                 compare,
                                                                 bcrash, ubexpr,
                                                                 loc);
-                known_valid = true;
                 break;
               }
             case NIL_CHECK_DEFAULT:
               go_unreachable();
           }
-        ret = gogo->backend()->indirect_expression(pbtype, bexpr,
-                                                   known_valid, loc);
+        ret = gogo->backend()->indirect_expression(pbtype, bexpr, false, loc);
       }
       break;
 
@@ -13339,7 +13336,8 @@  Array_index_expression::do_get_backend(Translate_context* context)
 
 	  Type* ele_type = this->array_->type()->array_type()->element_type();
 	  Btype* ele_btype = ele_type->get_backend(gogo);
-	  ret = gogo->backend()->indirect_expression(ele_btype, ptr, true, loc);
+	  ret = gogo->backend()->indirect_expression(ele_btype, ptr, false,
+						     loc);
 	}
       return ret;
     }
@@ -13679,7 +13677,7 @@  String_index_expression::do_get_backend(Translate_context* context)
     {
       ptr = gogo->backend()->pointer_offset_expression(ptr, bstart, loc);
       Btype* ubtype = Type::lookup_integer_type("uint8")->get_backend(gogo);
-      return gogo->backend()->indirect_expression(ubtype, ptr, true, loc);
+      return gogo->backend()->indirect_expression(ubtype, ptr, false, loc);
     }
 
   Expression* end = NULL;