diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-01 00:02:58 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-01 00:02:58 +0000 |
commit | a763aa92e52338e6ffb7e5b13fc30d49b5a89e93 (patch) | |
tree | 7a4e86ee3eebcb79ef218195e079b012dade5d34 | |
parent | 7d18953823ddbc315831578e6a7038a6138036c8 (diff) | |
download | gcc-a763aa92e52338e6ffb7e5b13fc30d49b5a89e93.zip gcc-a763aa92e52338e6ffb7e5b13fc30d49b5a89e93.tar.gz gcc-a763aa92e52338e6ffb7e5b13fc30d49b5a89e93.tar.bz2 |
compiler: Don't crash on type switch case nil with selector.
From-SVN: r183782
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 18 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.h | 3 |
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index e94090b..c65e47f 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -3848,6 +3848,24 @@ Variable::add_preinit_statement(Gogo* gogo, Statement* s) b->set_end_location(s->location()); } +// Whether this variable has a type. + +bool +Variable::has_type() const +{ + if (this->type_ == NULL) + return false; + + // A variable created in a type switch case nil does not actually + // have a type yet. It will be changed to use the initializer's + // type in determine_type. + if (this->is_type_switch_var_ + && this->type_->is_nil_constant_as_type()) + return false; + + return true; +} + // In an assignment which sets a variable to a tuple of EXPR, return // the type of the first element of the tuple. diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index 7d77c9f..2231e5d 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -1154,8 +1154,7 @@ class Variable // Return whether the type is defined yet. bool - has_type() const - { return this->type_ != NULL; } + has_type() const; // Get the initial value. Expression* |