public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7154] compiler: treat notinheap types as not being pointers
@ 2022-02-09 22:11 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-02-09 22:11 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:70feb6839fe1f13982eb03096bd1140b59881b76

commit r12-7154-g70feb6839fe1f13982eb03096bd1140b59881b76
Author: Ian Lance Taylor <iant@golang.org>
Date:   Tue Feb 8 20:22:32 2022 -0800

    compiler: treat notinheap types as not being pointers
    
    By definition, a type is marked notinheap doesn't contain any pointers
    that the garbage collector cares about, and neither does a pointer to
    such a type.  Change the type descriptors to consistently treat such
    types as not being pointers, by setting ptrdata to 0 and gcdata to nil.
    
    Change-Id: Id8466555ec493456ff5ff09f1670551414619bd2
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384118
    Trust: Ian Lance Taylor <iant@golang.org>
    Reviewed-by: Cherry Mui <cherryyz@google.com>

Diff:
---
 gcc/go/gofrontend/MERGE    |  2 +-
 gcc/go/gofrontend/gogo.cc  |  7 +++++--
 gcc/go/gofrontend/types.cc | 25 +++++++++++++++++++++----
 gcc/go/gofrontend/types.h  |  5 ++++-
 4 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 9cd22ef011e..3ea7aed3506 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-3b1e46937d11b043d0986a3dfefaee27454c3da0
+7dffb933d33ff288675c8094d05c31b35cbf7e4d
 
 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 b1e210ee6ac..30d5c9fcb0b 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -8869,10 +8869,13 @@ Named_object::get_backend(Gogo* gogo, std::vector<Bexpression*>& const_decls,
           {
             named_type->
                 type_descriptor_pointer(gogo, Linemap::predeclared_location());
-	    named_type->gc_symbol_pointer(gogo);
             Type* pn = Type::make_pointer_type(named_type);
             pn->type_descriptor_pointer(gogo, Linemap::predeclared_location());
-	    pn->gc_symbol_pointer(gogo);
+	    if (named_type->in_heap())
+	      {
+		named_type->gc_symbol_pointer(gogo);
+		pn->gc_symbol_pointer(gogo);
+	      }
           }
       }
       break;
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 1c67ea099eb..ee3467666d8 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -2513,13 +2513,18 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   Expression_list* vals = new Expression_list();
   vals->reserve(12);
 
-  if (!this->has_pointer())
+  bool has_pointer;
+  if (name != NULL)
+    has_pointer = name->has_pointer();
+  else
+    has_pointer = this->has_pointer();
+  if (!has_pointer)
     runtime_type_kind |= RUNTIME_TYPE_KIND_NO_POINTERS;
   if (this->is_direct_iface_type())
     runtime_type_kind |= RUNTIME_TYPE_KIND_DIRECT_IFACE;
   int64_t ptrsize;
   int64_t ptrdata;
-  if (this->needs_gcprog(gogo, &ptrsize, &ptrdata))
+  if (has_pointer && this->needs_gcprog(gogo, &ptrsize, &ptrdata))
     runtime_type_kind |= RUNTIME_TYPE_KIND_GC_PROG;
 
   Struct_field_list::const_iterator p = fields->begin();
@@ -2530,7 +2535,10 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
   ++p;
   go_assert(p->is_field_name("ptrdata"));
   type_info = Expression::TYPE_INFO_DESCRIPTOR_PTRDATA;
-  vals->push_back(Expression::make_type_info(this, type_info));
+  if (has_pointer)
+    vals->push_back(Expression::make_type_info(this, type_info));
+  else
+    vals->push_back(Expression::make_integer_ul(0, p->type(), bloc));
 
   ++p;
   go_assert(p->is_field_name("hash"));
@@ -2576,7 +2584,12 @@ Type::type_descriptor_constructor(Gogo* gogo, int runtime_type_kind,
 
   ++p;
   go_assert(p->is_field_name("gcdata"));
-  vals->push_back(Expression::make_gc_symbol(this));
+  if (has_pointer)
+    vals->push_back(Expression::make_gc_symbol(this));
+  else
+    vals->push_back(Expression::make_cast(p->type(),
+					  Expression::make_nil(bloc),
+					  bloc));
 
   ++p;
   go_assert(p->is_field_name("string"));
@@ -10894,6 +10907,10 @@ Named_type::do_verify()
 bool
 Named_type::do_has_pointer() const
 {
+  // A type that is not in the heap has no pointers that we care about.
+  if (!this->in_heap_)
+    return false;
+
   if (this->seen_)
     return false;
   this->seen_ = true;
diff --git a/gcc/go/gofrontend/types.h b/gcc/go/gofrontend/types.h
index a33453afc84..c55345a9d64 100644
--- a/gcc/go/gofrontend/types.h
+++ b/gcc/go/gofrontend/types.h
@@ -2300,9 +2300,12 @@ class Pointer_type : public Type
   do_verify()
   { return this->to_type_->verify(); }
 
+  // If this is a pointer to a type that can't be in the heap, then
+  // the garbage collector does not have to look at this, so pretend
+  // that this is not a pointer at all.
   bool
   do_has_pointer() const
-  { return true; }
+  { return this->to_type_->in_heap(); }
 
   bool
   do_compare_is_identity(Gogo*)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-09 22:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 22:11 [gcc r12-7154] compiler: treat notinheap types as not being pointers Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).