compiler: nil-checked pointers and index expressions can trap
authorIan Lance Taylor <iant@golang.org>
Wed, 23 Dec 2020 21:54:35 +0000 (13:54 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 23 Dec 2020 22:08:52 +0000 (14:08 -0800)
The compiler 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.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279960

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index fbac942ad428c7d2fcb9145e090333d243adb01a..600d976962493fa5448b1a2c617a22cf0c2f0dcb 100644 (file)
@@ -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.
index adc1ebb46437d5d687a0365984944d3c2f7afc48..17b4cfd2c197343ffce51843206f3d586d5e998b 100644 (file)
@@ -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;