Skip to content

Commit

Permalink
compiler: Don't crash on malformed numeric constants.
Browse files Browse the repository at this point in the history
Fixes golang/go#11548.

Change-Id: Iec9f69f4814af462680e36997be1bf54ebe839da
Reviewed-on: https://go-review.googlesource.com/13794
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
Chris Manghane authored and ianlancetaylor committed Sep 16, 2015
1 parent 01a574c commit 79f457a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions go/expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,13 @@ Integer_expression::do_check_types(Gogo*)
Bexpression*
Integer_expression::do_get_backend(Translate_context* context)
{
if (this->is_error_expression()
|| (this->type_ != NULL && this->type_->is_error_type()))
{
go_assert(saw_errors());
return context->gogo()->backend()->error_expression();
}

Type* resolved_type = NULL;
if (this->type_ != NULL && !this->type_->is_abstract())
resolved_type = this->type_;
Expand Down Expand Up @@ -2266,6 +2273,13 @@ Float_expression::do_check_types(Gogo*)
Bexpression*
Float_expression::do_get_backend(Translate_context* context)
{
if (this->is_error_expression()
|| (this->type_ != NULL && this->type_->is_error_type()))
{
go_assert(saw_errors());
return context->gogo()->backend()->error_expression();
}

Type* resolved_type;
if (this->type_ != NULL && !this->type_->is_abstract())
resolved_type = this->type_;
Expand Down Expand Up @@ -2448,6 +2462,13 @@ Complex_expression::do_check_types(Gogo*)
Bexpression*
Complex_expression::do_get_backend(Translate_context* context)
{
if (this->is_error_expression()
|| (this->type_ != NULL && this->type_->is_error_type()))
{
go_assert(saw_errors());
return context->gogo()->backend()->error_expression();
}

Type* resolved_type;
if (this->type_ != NULL && !this->type_->is_abstract())
resolved_type = this->type_;
Expand Down Expand Up @@ -2826,8 +2847,12 @@ Const_expression::do_check_types(Gogo*)
Bexpression*
Const_expression::do_get_backend(Translate_context* context)
{
if (this->type_ != NULL && this->type_->is_error())
return context->backend()->error_expression();
if (this->is_error_expression()
|| (this->type_ != NULL && this->type_->is_error()))
{
go_assert(saw_errors());
return context->backend()->error_expression();
}

// If the type has been set for this expression, but the underlying
// object is an abstract int or float, we try to get the abstract
Expand Down

0 comments on commit 79f457a

Please sign in to comment.