compiler, go/internal/gccgoimporter: export notinheap annotation
authorIan Lance Taylor <iant@golang.org>
Mon, 26 Oct 2020 23:48:03 +0000 (16:48 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Oct 2020 18:03:11 +0000 (11:03 -0700)
This is the gofrontend version of https://golang.org/cl/259297.
This is required now because that change is in the 1.15.3 release.

This requires changing the go/internal/gccgoimporter package, to skip
the new annotation. This change will need to be ported to the gc and
x/tools repos.

For golang/go#41761

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/265258

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/export.cc
gcc/go/gofrontend/import.cc
gcc/go/gofrontend/types.cc
gcc/go/gofrontend/types.h
libgo/go/go/internal/gccgoimporter/parser.go

index 6caece3..7d06595 100644 (file)
@@ -1,4 +1,4 @@
-4c1e7a083bdea02759cd5d2054038fb8a4a55ec8
+957591b8a054b692d92203a2420851689875f9c5
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 277aa74..90a5f6d 100644 (file)
@@ -1211,6 +1211,9 @@ Export::write_type_definition(const Type* type, int index)
       this->write_string(nt->named_object()->name());
       this->write_c_string("\" ");
 
       this->write_string(nt->named_object()->name());
       this->write_c_string("\" ");
 
+      if (!nt->in_heap())
+       this->write_c_string("notinheap ");
+
       if (nt->is_alias())
        this->write_c_string("= ");
     }
       if (nt->is_alias())
        this->write_c_string("= ");
     }
index c6c1178..f671416 100644 (file)
@@ -1049,6 +1049,13 @@ Import::read_named_type(int index)
       this->require_c_string(" ");
     }
 
       this->require_c_string(" ");
     }
 
+  bool in_heap = true;
+  if (this->match_c_string("notinheap"))
+    {
+      this->require_c_string("notinheap ");
+      in_heap = false;
+    }
+
   bool is_alias = false;
   if (this->match_c_string("= "))
     {
   bool is_alias = false;
   if (this->match_c_string("= "))
     {
@@ -1102,7 +1109,14 @@ Import::read_named_type(int index)
   // declaration of a type defined in some other file.
   Type* type;
   if (this->match_c_string(">") || this->match_c_string("\n"))
   // declaration of a type defined in some other file.
   Type* type;
   if (this->match_c_string(">") || this->match_c_string("\n"))
-    type = this->types_[index];
+    {
+      type = this->types_[index];
+      if (!in_heap)
+       go_error_at(this->location_,
+                   ("import error at %d for type index %d: "
+                    "forward declaration marked notinheap"),
+                   this->pos(), index);
+    }
   else
     {
       if (no->is_type_declaration())
   else
     {
       if (no->is_type_declaration())
@@ -1117,6 +1131,8 @@ Import::read_named_type(int index)
          // This type has not yet been imported.
          ntype->clear_is_visible();
 
          // This type has not yet been imported.
          ntype->clear_is_visible();
 
+         if (!in_heap)
+           ntype->set_not_in_heap();
          if (is_alias)
            ntype->set_is_alias();
 
          if (is_alias)
            ntype->set_is_alias();
 
index eb9c766..f3bcf2e 100644 (file)
@@ -6048,7 +6048,7 @@ Struct_type::do_hash_might_panic()
 // Return whether this struct type is permitted to be in the heap.
 
 bool
 // Return whether this struct type is permitted to be in the heap.
 
 bool
-Struct_type::do_in_heap()
+Struct_type::do_in_heap() const
 {
   const Struct_field_list* fields = this->fields_;
   if (fields == NULL)
 {
   const Struct_field_list* fields = this->fields_;
   if (fields == NULL)
index ccd1268..9ac8516 100644 (file)
@@ -667,7 +667,7 @@ class Type
 
   // Whether the type is permitted in the heap.
   bool
 
   // Whether the type is permitted in the heap.
   bool
-  in_heap()
+  in_heap() const
   { return this->do_in_heap(); }
 
   // Return a hash code for this type for the method hash table.
   { return this->do_in_heap(); }
 
   // Return a hash code for this type for the method hash table.
@@ -1120,7 +1120,7 @@ class Type
   { return false; }
 
   virtual bool
   { return false; }
 
   virtual bool
-  do_in_heap()
+  do_in_heap() const
   { return true; }
 
   virtual unsigned int
   { return true; }
 
   virtual unsigned int
@@ -2660,7 +2660,7 @@ class Struct_type : public Type
   do_hash_might_panic();
 
   bool
   do_hash_might_panic();
 
   bool
-  do_in_heap();
+  do_in_heap() const;
 
   unsigned int
   do_hash_for_method(Gogo*, int) const;
 
   unsigned int
   do_hash_for_method(Gogo*, int) const;
@@ -2842,7 +2842,7 @@ class Array_type : public Type
   { return this->length_ != NULL && this->element_type_->hash_might_panic(); }
 
   bool
   { return this->length_ != NULL && this->element_type_->hash_might_panic(); }
 
   bool
-  do_in_heap()
+  do_in_heap() const
   { return this->length_ == NULL || this->element_type_->in_heap(); }
 
   unsigned int
   { return this->length_ == NULL || this->element_type_->in_heap(); }
 
   unsigned int
@@ -3591,7 +3591,7 @@ class Named_type : public Type
   do_needs_key_update();
 
   bool
   do_needs_key_update();
 
   bool
-  do_in_heap()
+  do_in_heap() const
   { return this->in_heap_ && this->type_->in_heap(); }
 
   unsigned int
   { return this->in_heap_ && this->type_->in_heap(); }
 
   unsigned int
@@ -3754,7 +3754,7 @@ class Forward_declaration_type : public Type
   { return this->real_type()->needs_key_update(); }
 
   bool
   { return this->real_type()->needs_key_update(); }
 
   bool
-  do_in_heap()
+  do_in_heap() const
   { return this->real_type()->in_heap(); }
 
   unsigned int
   { return this->real_type()->in_heap(); }
 
   unsigned int
index e2ef33f..1b1d07d 100644 (file)
@@ -517,6 +517,13 @@ func (p *parser) parseNamedType(nlist []interface{}) types.Type {
                p.errorf("%v has nil type", obj)
        }
 
                p.errorf("%v has nil type", obj)
        }
 
+       if p.tok == scanner.Ident && p.lit == "notinheap" {
+               p.next()
+               // The go/types package has no way of recording that
+               // this type is marked notinheap. Presumably no user
+               // of this package actually cares.
+       }
+
        // type alias
        if p.tok == '=' {
                p.next()
        // type alias
        if p.tok == '=' {
                p.next()