From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 809E8385E036; Mon, 14 Mar 2022 10:35:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 809E8385E036 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: Various __intcap and __null fixes X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: b0775d04a58ac8b5a69251ae902c9306f785fcec X-Git-Newrev: 8eadbc50a134aa1e6dd465d91cdc9878d930ff33 Message-Id: <20220314103527.809E8385E036@sourceware.org> Date: Mon, 14 Mar 2022 10:35:27 +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, 14 Mar 2022 10:35:27 -0000 https://gcc.gnu.org/g:8eadbc50a134aa1e6dd465d91cdc9878d930ff33 commit 8eadbc50a134aa1e6dd465d91cdc9878d930ff33 Author: Alex Coplan Date: Tue Feb 8 15:56:13 2022 +0000 cp: Various __intcap and __null fixes GCC gives __null an INTCAP_TYPE when Pmode is a capability mode: this follows CHERI LLVM. The initial problem here was c_common_type_for_mode building new intcap type nodes instead of using the shared (u)intcap_type_node nodes. This meant these type nodes didn't go through the usual builtin type registration and consequently didn't have a TYPE_NAME. This in turn meant we called c_pretty_printer::simple_type_specifier on these types and hit ICEs due to the TYPE_PRECISION checks on capability types (as well as emitting sub-par diagnostics involving __null). This patch fixes both of these issues by: - Using the shared tree nodes in c_common_type_for_mode. - Adjusting the precision checks to use TYPE_CAP_PRECISION. Note we use c_common_type_for_mode (ptr_mode, 0) in c-common.c:c_common_nodes_and_builtins to build null_node (used for __null in C++, NULL is defined to this). Hence the need to fix c_common_type_for_mode when called with CADImode here. In this patch, we also implement various conversions that were found to be needed with __null having INTCAP_TYPE (and of course are needed for __intcap in general). We also adjust null_ptr_cst_p to recognize null pointer constants of INTCAP_TYPE. We adjust tsubst to handle substituting into an INTCAP_TYPE node (i.e. (u)intcap_type_node) by simply returning the node unmodified. It looks like the INTEGER_TYPE case is specifically for handling substituting into the TYPE_DOMAIN of an ARRAY_TYPE, so we needn't worry about that handling applying to INTCAP_TYPEs (the TYPE_DOMAIN of an array type is guaranteed to be an INTEGER_TYPE, and we intend to preserve that guarantee). gcc/c-family/ChangeLog: * c-common.c (c_common_type_for_mode): Use shared (u)intcap_type_node nodes instead of building a new one. * c-pretty-print.c (c_pretty_printer::simple_type_specifier): Adjust a couple of TYPE_PRECISION uses to TYPE_CAP_PRECISION. gcc/cp/ChangeLog: * call.c (null_ptr_cst_p): Recognize null pointer constants of INTCAP_TYPE: this is the type of __null under pure/fake-cap. (standard_conversion): Allow implicit conversion from INTCAP_TYPE to arithmetic types. * cvt.c (cp_convert_to_pointer): Implement __intcap -> pointer conversion. * pt.c (tsubst): Handle INTCAP_TYPE. * typeck.c (build_reinterpret_cast_1): Allow reinterpret_casting __intcap to pointer. Diff: --- gcc/c-family/c-common.c | 2 +- gcc/c-family/c-pretty-print.c | 4 ++-- gcc/cp/call.c | 5 +++-- gcc/cp/cvt.c | 3 +++ gcc/cp/pt.c | 1 + gcc/cp/typeck.c | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 650b1c94610..dd0ded25d9d 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2266,7 +2266,7 @@ c_common_type_for_mode (machine_mode mode, int unsignedp) else { gcc_assert (is_a (mode)); - return build_intcap_type_for_mode (mode, unsignedp); + return unsignedp ? uintcap_type_node : intcap_type_node; } } diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index 87e96845e2e..ddc29c67464 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -350,7 +350,7 @@ c_pretty_printer::simple_type_specifier (tree t) } else { - int prec = TYPE_PRECISION (t); + int prec = TYPE_CAP_PRECISION (t); tree common_t; if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t))) common_t = c_common_type_for_mode (TYPE_MODE (t), @@ -361,7 +361,7 @@ c_pretty_printer::simple_type_specifier (tree t) if (common_t && TYPE_NAME (common_t)) { simple_type_specifier (common_t); - if (TYPE_PRECISION (common_t) != prec) + if (TYPE_CAP_PRECISION (common_t) != prec) { pp_colon (this); pp_decimal_int (this, prec); diff --git a/gcc/cp/call.c b/gcc/cp/call.c index c0c52120e14..d083808b877 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -545,12 +545,12 @@ null_ptr_cst_p (tree t) /* Core issue 903 says only literal 0 is a null pointer constant. */ if (TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t) - && TREE_CODE (type) == INTEGER_TYPE + && (TREE_CODE (type) == INTEGER_TYPE || INTCAP_TYPE_P (type)) && integer_zerop (t) && !char_type_p (type)) return true; } - else if (CP_INTEGRAL_TYPE_P (type)) + else if (CP_INTEGRAL_TYPE_P (type) || INTCAP_TYPE_P (type)) { t = fold_non_dependent_expr (t, tf_none); STRIP_NOPS (t); @@ -1485,6 +1485,7 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, else if (ARITHMETIC_TYPE_P (to) || INTCAP_TYPE_P (to)) { if (! (INTEGRAL_CODE_P (fcode) + || fcode == INTCAP_TYPE || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL))) || SCOPED_ENUM_P (from)) return NULL; diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a36a3cce8af..182646674d3 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -243,6 +243,9 @@ cp_convert_to_pointer (tree type, tree expr, bool dofold, return error_mark_node; } + if (form == INTCAP_TYPE) + return convert_to_pointer_maybe_fold (type, expr, dofold); + if (INTEGRAL_CODE_P (form)) { if (capability_type_p (type)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5dbdd37f6e3..afea77c84c9 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15333,6 +15333,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) case BOOLEAN_TYPE: case NULLPTR_TYPE: case LANG_TYPE: + case INTCAP_TYPE: return t; case INTEGER_TYPE: diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 571e5ab36a9..c467cdbbfdf 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -7995,7 +7995,8 @@ build_reinterpret_cast_1 (location_t loc, tree type, tree expr, /* [expr.reinterpret.cast] A value of integral or enumeration type can be explicitly converted to a pointer. */ - else if (TYPE_PTR_P (type) && INTEGRAL_OR_ENUMERATION_TYPE_P (intype)) + else if (TYPE_PTR_P (type) && (INTEGRAL_OR_ENUMERATION_TYPE_P (intype) + || INTCAP_TYPE_P (intype))) /* OK */ ; else if ((INTEGRAL_OR_ENUMERATION_TYPE_P (type)