diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-12-23 13:54:35 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-12-23 14:08:52 -0800 |
commit | 3932785450fb74a886b8eb3d6f889de9766b7e8e (patch) | |
tree | 88f09a63109a96ea57a7bdf1cf6990f7ad68c3b8 /gcc/go | |
parent | 0a541e746c71fe21eb72bae61a9ead541ed7e98d (diff) | |
download | gcc-3932785450fb74a886b8eb3d6f889de9766b7e8e.zip gcc-3932785450fb74a886b8eb3d6f889de9766b7e8e.tar.gz gcc-3932785450fb74a886b8eb3d6f889de9766b7e8e.tar.bz2 |
compiler: nil-checked pointers and index expressions can trap
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
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 10 |
2 files changed, 5 insertions, 7 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index fbac942..600d976 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 adc1ebb..17b4cfd 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; |