public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] cp: Explicitly null-derive some pointers
@ 2022-02-28 12:09 Matthew Malcomson
0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-02-28 12:09 UTC (permalink / raw)
To: gcc-cvs
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);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-02-28 12:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 12:09 [gcc(refs/vendors/ARM/heads/morello)] cp: Explicitly null-derive some pointers Matthew Malcomson
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).