public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/morello)] cp: Explicitly null-derive some pointers
Date: Mon, 28 Feb 2022 12:09:26 +0000 (GMT)	[thread overview]
Message-ID: <20220228120926.00935385801A@sourceware.org> (raw)

https://gcc.gnu.org/g:f58ba93e83426e0c296e71b19eac7a64cfdc2cf5

commit f58ba93e83426e0c296e71b19eac7a64cfdc2cf5
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Fri Jan 28 16:17:42 2022 +0000

    cp: Explicitly null-derive some pointers
    
    The C++ frontend sometimes constructs pointers from constant integers by
    directly converting them. This patch null-derives these instead in a
    couple of places to avoid ICEs.
    
    gcc/cp/ChangeLog:
    
            * class.c (build_rtti_vtbl_entries): We can't simply convert
            integers into capability pointers: null-derive these instead
            (e.g. when putting an offset into a vtable).
            * method.c (build_stub_object): When building our dummy
            reference, null-derive a capability instead of just trying to
            convert integer_one_node into a capability type.

Diff:
---
 gcc/cp/class.c  | 7 ++++++-
 gcc/cp/method.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index b39bdaaa3ab..0202216ad39 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -10209,7 +10209,9 @@ build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   if (flag_rtti)
     decl = build_address (get_tinfo_decl (t));
   else
-    decl = integer_zero_node;
+    decl = capability_type_p (vfunc_ptr_type_node)
+      ? null_pointer_node
+      : integer_zero_node;
 
   /* Convert the declaration to a type that can be stored in the
      vtable.  */
@@ -10219,6 +10221,9 @@ build_rtti_vtbl_entries (tree binfo, vtbl_init_data* vid)
   /* Add the offset-to-top entry.  It comes earlier in the vtable than
      the typeinfo entry.  Convert the offset to look like a
      function pointer, so that we can put it in the vtable.  */
+  if (capability_type_p (vfunc_ptr_type_node))
+    offset = fold_build_pointer_plus (null_pointer_node, offset);
+
   init = build_nop (vfunc_ptr_type_node, offset);
   CONSTRUCTOR_APPEND_ELT (vid->inits, NULL_TREE, init);
 }
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 1058fd05a7d..ae154ef2872 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1627,7 +1627,14 @@ build_stub_object (tree reftype)
 {
   if (!TYPE_REF_P (reftype))
     reftype = cp_build_reference_type (reftype, /*rval*/true);
-  tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
+
+  tree one = integer_one_node;
+
+  /* For purecap, we must explicitly null-derive the capability.  */
+  if (capability_type_p (reftype))
+    one = fold_build_pointer_plus (null_pointer_node, one);
+
+  tree stub = build1 (CONVERT_EXPR, reftype, one);
   return convert_from_reference (stub);
 }


                 reply	other threads:[~2022-02-28 12:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220228120926.00935385801A@sourceware.org \
    --to=matmal01@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).