From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 00935385801A; Mon, 28 Feb 2022 12:09:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00935385801A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] cp: Explicitly null-derive some pointers X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: c765078578688e8a16e6632c7180b0b2389ccd55 X-Git-Newrev: f58ba93e83426e0c296e71b19eac7a64cfdc2cf5 Message-Id: <20220228120926.00935385801A@sourceware.org> Date: Mon, 28 Feb 2022 12:09:26 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Feb 2022 12:09:26 -0000 https://gcc.gnu.org/g:f58ba93e83426e0c296e71b19eac7a64cfdc2cf5 commit f58ba93e83426e0c296e71b19eac7a64cfdc2cf5 Author: Alex Coplan 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); }