public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Fix loss of CAP_ADDR_EXPR when using build_fold_addr_expr
@ 2022-05-06 14:44 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:44 UTC (permalink / raw)
  To: gcc-cvs

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

commit aa8f65853fdc4454e32c9adb8692dc6e0d527e85
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Thu Apr 21 11:45:04 2022 +0100

    Fix loss of CAP_ADDR_EXPR when using build_fold_addr_expr
    
    This patch fixes another case in which code looks through an
    ADDR_EXPR and creates a new one based on the underlying base.
    The new ADDR_EXPR must be the same tree_code as the old one.

Diff:
---
 gcc/fold-const.c                                   | 11 ++++++++
 gcc/fold-const.h                                   | 13 ++++++++--
 gcc/gimple-laddress.c                              |  3 ++-
 .../gcc.target/aarch64/morello/pointer-arith-5.c   | 30 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e848b4c00b2..5f1db095cf6 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8764,6 +8764,17 @@ build_fold_addr_expr_loc (location_t loc, tree t)
   return build_fold_addr_expr_with_type_loc (loc, t, ptrtype);
 }
 
+/* Build an expression for the address of T, calculated by *ADDR_EXPR
+   code ADDR_EXPR.  */
+
+tree
+build_fold_addr_expr_loc (location_t loc, tree_code addr_expr, tree t)
+{
+  tree ptrtype = addr_expr_type (addr_expr, TREE_TYPE (t));
+
+  return build_fold_addr_expr_with_type_loc (loc, t, ptrtype);
+}
+
 /* Fold a unary expression of code CODE and type TYPE with operand
    OP0.  Return the folded expression if folding is successful.
    Otherwise, return NULL_TREE.  */
diff --git a/gcc/fold-const.h b/gcc/fold-const.h
index 4406c74056e..738e2d0fc51 100644
--- a/gcc/fold-const.h
+++ b/gcc/fold-const.h
@@ -122,9 +122,18 @@ extern bool wide_int_binop (wide_int &res, enum tree_code,
 			    const wide_int &arg1, const wide_int &arg2,
 			    signop, wi::overflow_type *);
 extern tree int_const_binop (enum tree_code, const_tree, const_tree, int = 1);
-#define build_fold_addr_expr(T)\
-        build_fold_addr_expr_loc (UNKNOWN_LOCATION, (T))
 extern tree build_fold_addr_expr_loc (location_t, tree);
+inline tree
+build_fold_addr_expr (tree op)
+{
+  return build_fold_addr_expr_loc (UNKNOWN_LOCATION, op);
+}
+extern tree build_fold_addr_expr_loc (location_t, tree_code, tree);
+inline tree
+build_fold_addr_expr (tree_code addr_expr, tree op)
+{
+  return build_fold_addr_expr_loc (UNKNOWN_LOCATION, addr_expr, op);
+}
 #define build_fold_addr_expr_with_type(T,TYPE)\
         build_fold_addr_expr_with_type_loc (UNKNOWN_LOCATION, (T), TYPE)
 extern tree build_fold_addr_expr_with_type_loc (location_t, tree, tree);
diff --git a/gcc/gimple-laddress.c b/gcc/gimple-laddress.c
index 9a8d11c7637..4660b64abd6 100644
--- a/gcc/gimple-laddress.c
+++ b/gcc/gimple-laddress.c
@@ -110,11 +110,12 @@ pass_laddress::execute (function *fun)
 	  poly_int64 bytepos = exact_div (bitpos, BITS_PER_UNIT);
 	  if (offset != NULL_TREE)
 	    {
+	      tree_code addr_expr = gimple_assign_rhs_code (stmt);
 	      if (maybe_ne (bytepos, 0))
 		offset = size_binop (PLUS_EXPR, offset, size_int (bytepos));
 	      offset = force_gimple_operand_gsi (&gsi, offset, true, NULL,
 						 true, GSI_SAME_STMT);
-	      base = build_fold_addr_expr (base);
+	      base = build_fold_addr_expr (addr_expr, base);
 	      base = force_gimple_operand_gsi (&gsi, base, true, NULL,
 					       true, GSI_SAME_STMT);
 	      gimple *g = gimple_build_assign (gimple_assign_lhs (stmt),
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-5.c b/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-5.c
new file mode 100644
index 00000000000..4c331376e1c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-5.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+
+struct GTeth_desc
+{
+  unsigned ed_cmdsts;
+};
+struct GTeth_softc
+{
+  struct GTeth_desc txq_desc[32];
+  unsigned int txq_fi;
+  unsigned int txq_nactive;
+};
+
+void GTeth_txq_free (struct GTeth_softc *sc);
+
+void
+GTeth_txq_done (struct GTeth_softc *__capability sc)
+{
+  while (sc->txq_nactive > 0)
+    {
+      volatile struct GTeth_desc *txd
+	= (volatile struct GTeth_desc *) &sc->txq_desc[sc->txq_fi];
+      if (txd->ed_cmdsts)
+	{
+	  if (sc->txq_nactive == 1)
+	    return;
+	}
+      GTeth_txq_free (sc);
+    }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-06 14:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:44 [gcc(refs/vendors/ARM/heads/morello)] Fix loss of CAP_ADDR_EXPR when using build_fold_addr_expr 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).