diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-14 23:42:53 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-14 23:42:53 +0000 |
commit | b901cf9dd9d20c6e0fe0b2eb32063a9b4930d1f6 (patch) | |
tree | b5046d7e4b60ff1ae9c5a213b054d41dc1cd4f70 /gcc/go | |
parent | 3466430f382b6adc2363721056b9abde3acd790a (diff) | |
download | gcc-b901cf9dd9d20c6e0fe0b2eb32063a9b4930d1f6.zip gcc-b901cf9dd9d20c6e0fe0b2eb32063a9b4930d1f6.tar.gz gcc-b901cf9dd9d20c6e0fe0b2eb32063a9b4930d1f6.tar.bz2 |
compiler: avoid crash on erroneous type
If there is an error constructing the backend type, the GCC backend
will report that the size is 1. That will then cause construction of
the ptrmask to crash. Avoid that case by just generating an empty
ptrmask.
Noticed while compiling a broken package. The policy I've been
following is to not commit a test case for a compiler crash on invalid
code, so no test case.
Reviewed-on: https://go-review.googlesource.com/45775
From-SVN: r249208
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 16 |
2 files changed, 12 insertions, 6 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 1f600d3..0eeac9b 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -372e75503c1dc9a38d9978aa6b67631283d5d6dd +6449e2832eef94eacf89c88fa16bede637f729ba 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/types.cc b/gcc/go/gofrontend/types.cc index 61a3363..912a23e 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -2570,16 +2570,16 @@ Type::make_gc_symbol_var(Gogo* gogo) bool Type::needs_gcprog(Gogo* gogo, int64_t* ptrsize, int64_t* ptrdata) { + Type* voidptr = Type::make_pointer_type(Type::make_void_type()); + if (!voidptr->backend_type_size(gogo, ptrsize)) + go_unreachable(); + if (!this->backend_type_ptrdata(gogo, ptrdata)) { go_assert(saw_errors()); return false; } - Type* voidptr = Type::make_pointer_type(Type::make_void_type()); - if (!voidptr->backend_type_size(gogo, ptrsize)) - go_unreachable(); - return *ptrdata / *ptrsize > max_ptrmask_bytes; } @@ -2795,7 +2795,13 @@ Bvariable* Type::gc_ptrmask_var(Gogo* gogo, int64_t ptrsize, int64_t ptrdata) { Ptrmask ptrmask(ptrdata / ptrsize); - ptrmask.set_from(gogo, this, ptrsize, 0); + if (ptrdata >= ptrsize) + ptrmask.set_from(gogo, this, ptrsize, 0); + else + { + // This can happen in error cases. Just build an empty gcbits. + go_assert(saw_errors()); + } std::string sym_name = "runtime.gcbits." + ptrmask.symname(); Bvariable* bvnull = NULL; std::pair<GC_gcbits_vars::iterator, bool> ins = |