aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-07-31 22:16:12 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-07-31 22:16:12 +0000
commit04628a1d33dca0c560af130475458313507cf9aa (patch)
tree8ba8d7038b89a56101535a903784fc22051f9b5d /gcc/go
parent3176040661d29d245759c8c686e247c35f305823 (diff)
downloadgcc-04628a1d33dca0c560af130475458313507cf9aa.zip
gcc-04628a1d33dca0c560af130475458313507cf9aa.tar.gz
gcc-04628a1d33dca0c560af130475458313507cf9aa.tar.bz2
compiler: Check the type in function declarations.
Function declarations don't create a block where the variables listed in the parameter list are declared. Because there are no variables declared, the types of the parameter variables is unchecked, allowing for invalid values to be used as the type. This patch adds a special case to the check_types pass for function declarations. Fixes golang/go#11567. Reviewed-on: https://go-review.googlesource.com/12662 From-SVN: r226456
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/gogo.cc31
-rw-r--r--gcc/go/gofrontend/gogo.h4
3 files changed, 36 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 6afd1ef..732b33d 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-19f0ec56bf278a9cbb100c6b24ec1a12c95ec41a
+bc4dda16f8686ab6e7335adfdfd2c6cc81cb2eb5
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/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 0824102..77b4d52 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3258,6 +3258,17 @@ Gogo::check_types()
{
Check_types_traverse traverse(this);
this->traverse(&traverse);
+
+ Bindings* bindings = this->current_bindings();
+ for (Bindings::const_declarations_iterator p = bindings->begin_declarations();
+ p != bindings->end_declarations();
+ ++p)
+ {
+ // Also check the types in a function declaration's signature.
+ Named_object* no = p->second;
+ if (no->is_function_declaration())
+ no->func_declaration_value()->check_types();
+ }
}
// Check the types in a single block.
@@ -5297,6 +5308,26 @@ Function_declaration::build_backend_descriptor(Gogo* gogo)
}
}
+// Check that the types used in this declaration's signature are defined.
+// Reports errors for any undefined type.
+
+void
+Function_declaration::check_types() const
+{
+ // Calling Type::base will give errors for any undefined types.
+ Function_type* fntype = this->type();
+ if (fntype->receiver() != NULL)
+ fntype->receiver()->type()->base();
+ if (fntype->parameters() != NULL)
+ {
+ const Typed_identifier_list* params = fntype->parameters();
+ for (Typed_identifier_list::const_iterator p = params->begin();
+ p != params->end();
+ ++p)
+ p->type()->base();
+ }
+}
+
// Return the function's decl after it has been built.
Bfunction*
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 51f628f..ece7e0f 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -1394,6 +1394,10 @@ class Function_declaration
export_func(Export* exp, const std::string& name) const
{ Function::export_func_with_type(exp, name, this->fntype_); }
+ // Check that the types used in this declaration's signature are defined.
+ void
+ check_types() const;
+
private:
// The type of the function.
Function_type* fntype_;