public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] cp: Some initial handling of capability conversions
@ 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:f1d1def4ac65449df59e8e6ca308cd815c0a4192

commit f1d1def4ac65449df59e8e6ca308cd815c0a4192
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Thu Jan 27 16:10:24 2022 +0000

    cp: Some initial handling of capability conversions
    
    The change in convert_to_integer_1 enables calling drop_capability on a
    capability of NULLPTR_TYPE. We haven't seen this to date as this type is
    only used by the C++ frontend.
    
    The change in cp_build_binary_op ensures we compare the address value of
    capability operands (as opposed to the capabilities themselves) and the
    change in cp_build_unary_op ensures we use a non-capability type for the
    increment amount.
    
    gcc/ChangeLog:
    
            * convert.c (convert_to_integer_1): Also handle NULLPTR_TYPE.
    
    gcc/cp/ChangeLog:
    
            * typeck.c (cp_build_binary_op): For comparisons, ensure we use a
            non-capability type as the common type for the arguments.
            (cp_build_unary_op): Ensure we use a non-capability type for the
            increment amount (since this is an offset).

Diff:
---
 gcc/convert.c   | 1 +
 gcc/cp/typeck.c | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/convert.c b/gcc/convert.c
index 596634ce46f..347f44c4ace 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -680,6 +680,7 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
     case INTCAP_TYPE:
     case POINTER_TYPE:
     case REFERENCE_TYPE:
+    case NULLPTR_TYPE:
       if (integer_zerop (expr)
 	  && !TREE_OVERFLOW (tree_strip_any_location_wrapper (expr)))
 	return build_int_cst (type, 0);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 3bb98bcd465..ac30f4b4133 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5230,6 +5230,9 @@ cp_build_binary_op (const op_location_t &location,
 				       type0));
 	}
 
+      /* Comparisons should always be done on the address value, not on the
+	 capability.  */
+      result_type = noncapability_type (result_type);
       break;
 
     case MAX_EXPR:
@@ -5382,6 +5385,9 @@ cp_build_binary_op (const op_location_t &location,
 	  instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
 	}
 
+      /* Comparisons should always be done on the address value, not on
+	 capabilities.  */
+      result_type = noncapability_type (result_type);
       break;
 
     case UNORDERED_EXPR:
@@ -6702,7 +6708,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
 	    ? build_one_cst (argtype)
 	    : integer_one_node;
 
-	inc = cp_convert (argtype, inc, complain);
+	inc = cp_convert (noncapability_type (argtype), inc, complain);
 
 	/* If 'arg' is an Objective-C PROPERTY_REF expression, then we
 	   need to ask Objective-C to build the increment or decrement


^ 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: Some initial handling of capability conversions 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).