diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:46:07 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:46:07 +0000 |
commit | 4cff15eaca92180183608371351ba2c818990304 (patch) | |
tree | 21ff74b0c1fdd336b5e4670a87171eb39befb6c5 /gcc | |
parent | 91cb7f7804da1e4974e1e3589822e10910eeae20 (diff) | |
download | gcc-4cff15eaca92180183608371351ba2c818990304.zip gcc-4cff15eaca92180183608371351ba2c818990304.tar.gz gcc-4cff15eaca92180183608371351ba2c818990304.tar.bz2 |
compiler: give error for non-int arguments to make
This implements a requirement of the language spec.
While we're here fix the value returned by the type method of a
builtin call expression to make, although this doesn't seem to make
any difference anywhere since we lower this to a runtime call before
the determine_types pass anyhow.
There is already a test for this error in the master repository:
test/fixedbugs/issue16949.go. It just hasn't made it into the gccgo
testsuite yet.
Fixes golang/go#16949
Reviewed-on: https://go-review.googlesource.com/91697
From-SVN: r257376
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index a893731..edfec39 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -0c8c4fca4b52bc2323561a432436af5343e0f7b4 +312af623f48633989e9eb6e559ede84a23998ece 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 c90ef8d..715f625 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -7497,6 +7497,11 @@ Builtin_call_expression::lower_make(Statement_inserter* inserter) { len_arg = *parg; len_arg->determine_type(&int_context); + if (len_arg->type()->integer_type() == NULL) + { + go_error_at(len_arg->location(), "non-integer len argument in make"); + return Expression::make_error(this->location()); + } if (!this->check_int_value(len_arg, true, &len_small)) return Expression::make_error(this->location()); ++parg; @@ -7512,6 +7517,11 @@ Builtin_call_expression::lower_make(Statement_inserter* inserter) { cap_arg = *parg; cap_arg->determine_type(&int_context); + if (cap_arg->type()->integer_type() == NULL) + { + go_error_at(cap_arg->location(), "non-integer cap argument in make"); + return Expression::make_error(this->location()); + } if (!this->check_int_value(cap_arg, false, &cap_small)) return Expression::make_error(this->location()); @@ -8306,7 +8316,6 @@ Builtin_call_expression::do_type() return Type::make_error_type(); case BUILTIN_NEW: - case BUILTIN_MAKE: { const Expression_list* args = this->args(); if (args == NULL || args->empty()) @@ -8314,6 +8323,14 @@ Builtin_call_expression::do_type() return Type::make_pointer_type(args->front()->type()); } + case BUILTIN_MAKE: + { + const Expression_list* args = this->args(); + if (args == NULL || args->empty()) + return Type::make_error_type(); + return args->front()->type(); + } + case BUILTIN_CAP: case BUILTIN_COPY: case BUILTIN_LEN: |