From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2109) id 7779E385782B; Tue, 22 Nov 2022 12:43:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7779E385782B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669120992; bh=JCjxE+vK5gJHbl/HrUO22Wwefl3pb9mylVERvsJWGJ4=; h=From:To:Subject:Date:From; b=AYP+SEzlO4JNcyvyqIf6mpc5ISC9yzSzJHRVdNkicTVEqB7iZQhslNPNlka/qQhQ6 RCkRrDhjjB7G09pQ9U2BkiQoAMd015qyeaz8J93EL0G6xpTgXJviRv+UfNVlQ7sKHN 0GqHwia7391F76Eq6s6RRcOw1skxYiH2ZoOHkhjA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Stam Markianos-Wright To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] c, cp: Remove drop_intcap helper X-Act-Checkin: gcc X-Git-Author: Alex Coplan X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 535b95325abf4d9b6f0fe3fed29874e42b8ac4d0 X-Git-Newrev: c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01 Message-Id: <20221122124312.7779E385782B@sourceware.org> Date: Tue, 22 Nov 2022 12:43:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01 commit c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01 Author: Alex Coplan Date: Tue Nov 8 16:32:50 2022 +0000 c, cp: Remove drop_intcap helper I noticed that the test intcap-const-pedwarn.c in morello.exp was failing on hybrid. On further investigation the cause appears to be the drop_intcap helper that we use when processing candidate integer constant expressions. Consider for example: enum { e = (unsigned __intcap)(int *)1 }; for purecap Morello, in c-decl.c:build_enumerator, we get the IR: arg:0 constant 1>> but for hybrid Morello, we get: arg:0 constant 1>> which is similar to what we get for the related testcase: enum { e = (unsigned long)(int *)1 }; on baseline AArch64: arg:0 constant 1>> As written, drop_intcap will strip nop_exprs converting from INTCAP_TYPE, but looking at the IR we get both for hybrid and baseline AArch64, it appears we shouldn't be sripping these conversions, since the identity nop_exprs seem to be what is used to trip the pedwarn in build_enumerator and other such places. Note also that drop_intcap doesn't appear to be necessary with the current folding. For cases like: enum { e = (unsigned __intcap)1 }; we just get an intcap-typed integer_cst: constant 1> so we correctly avoid diagnosing this case altogether, since we already have a bare integer_cst. Overall, it seems like the idea of drop_intcap was a mistake. This patch removes it from the compiler. This fixes the intcap-const-pedwarn.c test on hybrid and doesn't appear to regress elsewhere. Diff: --- gcc/c-family/c-common.c | 28 +--------------------------- gcc/c-family/c-common.h | 1 - gcc/c/c-decl.c | 5 ----- gcc/c/c-typeck.c | 8 -------- gcc/cp/class.c | 3 ++- 5 files changed, 3 insertions(+), 42 deletions(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f554598c9ac..7f48e050235 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2089,7 +2089,7 @@ check_case_value (location_t loc, tree value) if (TREE_CODE (value) == INTEGER_CST) /* Promote char or short to int. */ - value = perform_integral_promotions (drop_intcap (value)); + value = perform_integral_promotions (drop_capability (value)); else if (value != error_mark_node) { error_at (loc, "case label does not reduce to an integer constant"); @@ -2649,32 +2649,6 @@ drop_capability (tree t) return convert (noncapability_type (TREE_TYPE (t)), t); } -/* A more lightweight version of drop_capability suitable for use on - candidate integer constant expressions (possibly involving - INTCAP_TYPEs). It aims to return an INTEGER_CST of INTEGER_TYPE - without stripping conversions that would be forbidden in an integer - constant expression (e.g. conversions to pointer type). */ - -tree -drop_intcap (tree t) -{ - if (!INTCAP_TYPE_P (TREE_TYPE (t))) - return t; - - if (TREE_CODE (t) == INTEGER_CST) - return drop_capability (t); - - /* We can drop NOP_EXPRs from other integer types. */ - if (TREE_CODE (t) == NOP_EXPR) - { - auto ty = TREE_TYPE (TREE_OPERAND (t, 0)); - if (INTEGRAL_TYPE_P (ty) || INTCAP_TYPE_P (ty)) - return drop_intcap (TREE_OPERAND (t, 0)); - } - - return t; -} - /* Convert from a non-capability type to a capability. This conversion will necessarily produce a capability that cannot be accessed, but that is fitting with the C semantics of converting diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 11be2b1c81f..ce07aabf49a 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -818,7 +818,6 @@ extern void c_register_addr_space (const char *str, addr_space_t as); /* In c-common.c. */ extern tree drop_capability (tree); -extern tree drop_intcap (tree); extern bool in_late_binary_op; extern const char *c_addr_space_name (addr_space_t as); extern tree identifier_global_value (tree); diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index bb503862786..23aebda70de 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5786,7 +5786,6 @@ check_bitfield_type_and_width (location_t loc, tree *type, tree *width, ? identifier_to_locale (IDENTIFIER_POINTER (orig_name)) : _("")); - *width = drop_intcap (*width); /* Detect and ignore out of range field width and process valid field widths. */ @@ -6518,8 +6517,6 @@ grokdeclarator (const struct c_declarator *declarator, if (size) { - size = drop_intcap (size); - bool size_maybe_const = true; bool size_int_const = (TREE_CODE (size) == INTEGER_CST && !TREE_OVERFLOW (size)); @@ -9141,8 +9138,6 @@ build_enumerator (location_t decl_loc, location_t loc, if (value != NULL_TREE) { - value = drop_intcap (value); - if (!INTEGRAL_TYPE_P (TREE_TYPE (value)) && !INTCAP_TYPE_P (TREE_TYPE (value))) { diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index b30442e3c29..cc832622165 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9305,10 +9305,6 @@ set_init_index (location_t loc, tree first, tree last, designator_erroneous = 1; - first = drop_intcap (first); - if (last) - last = drop_intcap (last); - if ((!INTEGRAL_TYPE_P (TREE_TYPE (first)) && !INTCAP_TYPE_P (TREE_TYPE (first))) || (last @@ -11271,8 +11267,6 @@ do_case (location_t loc, tree low_value, tree high_value) if (low_value) { - low_value = drop_intcap (low_value); - if (TREE_CODE (low_value) != INTEGER_CST) { low_value = c_fully_fold (low_value, false, NULL); @@ -11288,8 +11282,6 @@ do_case (location_t loc, tree low_value, tree high_value) if (high_value) { - high_value = drop_intcap (high_value); - if (TREE_CODE (high_value) != INTEGER_CST) { high_value = c_fully_fold (high_value, false, NULL); diff --git a/gcc/cp/class.c b/gcc/cp/class.c index cf69361b86a..a89ce4757e7 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3400,7 +3400,8 @@ check_bitfield_decl (tree field) w = cxx_constant_value (w); input_location = loc; - w = drop_intcap (w); + if (INTCAP_TYPE_P (TREE_TYPE (w))) + w = drop_capability (w); if (TREE_CODE (w) != INTEGER_CST) {