public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] c, cp: Remove drop_intcap helper
@ 2022-11-22 12:43 Stam Markianos-Wright
  0 siblings, 0 replies; 2+ messages in thread
From: Stam Markianos-Wright @ 2022-11-22 12:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01

commit c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01
Author: Alex Coplan <alex.coplan@arm.com>
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:
    
    <nop_expr
      type <intcap_type ... unsigned __intcap>
      arg:0 <integer_cst ... type <pointer_type ...> constant 1>>
    
    but for hybrid Morello, we get:
    
    <nop_expr
      type <intcap_type ... unsigned __intcap>
      arg:0 <integer_cst ... type <intcap_type ... unsigned __intcap> constant 1>>
    
    which is similar to what we get for the related testcase:
    
    enum {
      e = (unsigned long)(int *)1
    };
    
    on baseline AArch64:
    
    <nop_expr
      type <integer_type ... long unsigned int ...>
      arg:0 <integer_cst ... type <integer_type ... long unsigned int> 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:
    
    <integer_cst ... type <intcap_type ... unsigned __intcap> 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))
 		      : _("<anonymous>"));
 
-  *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)
 	{

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/vendors/ARM/heads/morello)] c, cp: Remove drop_intcap helper
@ 2022-11-14 13:24 Alex Coplan
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Coplan @ 2022-11-14 13:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01

commit c5fc2e2b80a4b192ffdbaf416033c7c62c9fef01
Author: Alex Coplan <alex.coplan@arm.com>
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:
    
    <nop_expr
      type <intcap_type ... unsigned __intcap>
      arg:0 <integer_cst ... type <pointer_type ...> constant 1>>
    
    but for hybrid Morello, we get:
    
    <nop_expr
      type <intcap_type ... unsigned __intcap>
      arg:0 <integer_cst ... type <intcap_type ... unsigned __intcap> constant 1>>
    
    which is similar to what we get for the related testcase:
    
    enum {
      e = (unsigned long)(int *)1
    };
    
    on baseline AArch64:
    
    <nop_expr
      type <integer_type ... long unsigned int ...>
      arg:0 <integer_cst ... type <integer_type ... long unsigned int> 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:
    
    <integer_cst ... type <intcap_type ... unsigned __intcap> 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))
 		      : _("<anonymous>"));
 
-  *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)
 	{

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-22 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 12:43 [gcc(refs/vendors/ARM/heads/morello)] c, cp: Remove drop_intcap helper Stam Markianos-Wright
  -- strict thread matches above, loose matches on Subject: below --
2022-11-14 13:24 Alex Coplan

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).