public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Properly parse invariant &MEM addresses in the GIMPLE FE
@ 2021-10-06  9:09 Richard Biener
  2021-10-06 16:25 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2021-10-06  9:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: joseph

Currently the frontend rejects those addresses as not lvalues
because the C frontend doens't expect MEM_REF or TARGET_MEM_REF
to appear (but they would be valid lvalues there).  The following
fixes that by amending lvalue_p.

The change also makes the dumping of the source of the testcase
valid for the GIMPLE FE by not eliding the '&' when dumping
string literals.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Joseph, is the C frontend change OK?

Thanks,
Richard.

2021-10-06  Richard Biener  <rguenther@suse.de>

gcc/c/
	* c-typeck.c (lvalue_p): Also allow MEM_REF and TARGET_MEM_REF.

gcc/
	* tree-pretty-print.c (dump_generic_node): Do not elide
	printing '&' when dumping with -gimple.

gcc/testsuite/
	* gcc.dg/gimplefe-47.c: New testcase.
---
 gcc/c/c-typeck.c                   |  4 ++++
 gcc/testsuite/gcc.dg/gimplefe-47.c | 27 +++++++++++++++++++++++++++
 gcc/tree-pretty-print.c            |  7 +++++--
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-47.c

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index f9eb0e5176f..0aac978c02e 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -4968,6 +4968,10 @@ lvalue_p (const_tree ref)
     case STRING_CST:
       return true;
 
+    case MEM_REF:
+    case TARGET_MEM_REF:
+      /* MEM_REFs can appear from -fgimple parsing or folding, so allow them
+	 here as well.  */
     case INDIRECT_REF:
     case ARRAY_REF:
     case VAR_DECL:
diff --git a/gcc/testsuite/gcc.dg/gimplefe-47.c b/gcc/testsuite/gcc.dg/gimplefe-47.c
new file mode 100644
index 00000000000..3bbd34d669f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-47.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+char * begfield (int tab, char * ptr, char * lim, int sword, int schar);
+
+int __GIMPLE (ssa)
+main ()
+{
+  char * lim;
+  char * s;
+  char * _1;
+
+  __BB(2):
+  _1 = begfield (58, ":ab", &__MEM <char[4]> ((void *)&":ab" + _Literal
+(void *) 3), 1, 1);
+  if (_1 != _Literal (char *) &__MEM <char[4]> ((void *)&":ab" + _Literal (void *) 2))
+    goto __BB3;
+  else
+    goto __BB4;
+
+  __BB(3):
+  __builtin_abort ();
+
+  __BB(4):
+  __builtin_exit (0);
+}
+
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index 30a3945c37c..275dc7d8af7 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -2888,10 +2888,13 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
     case PREDECREMENT_EXPR:
     case PREINCREMENT_EXPR:
     case INDIRECT_REF:
-      if (TREE_CODE (node) == ADDR_EXPR
+      if (!(flags & TDF_GIMPLE)
+	  && TREE_CODE (node) == ADDR_EXPR
 	  && (TREE_CODE (TREE_OPERAND (node, 0)) == STRING_CST
 	      || TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL))
-	;	/* Do not output '&' for strings and function pointers.  */
+	/* Do not output '&' for strings and function pointers when not
+	   dumping GIMPLE FE syntax.  */
+	;
       else
 	pp_string (pp, op_symbol (node));
 
-- 
2.31.1

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

* Re: [PATCH] Properly parse invariant &MEM addresses in the GIMPLE FE
  2021-10-06  9:09 [PATCH] Properly parse invariant &MEM addresses in the GIMPLE FE Richard Biener
@ 2021-10-06 16:25 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2021-10-06 16:25 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Wed, 6 Oct 2021, Richard Biener via Gcc-patches wrote:

> Currently the frontend rejects those addresses as not lvalues
> because the C frontend doens't expect MEM_REF or TARGET_MEM_REF
> to appear (but they would be valid lvalues there).  The following
> fixes that by amending lvalue_p.
> 
> The change also makes the dumping of the source of the testcase
> valid for the GIMPLE FE by not eliding the '&' when dumping
> string literals.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> Joseph, is the C frontend change OK?

Yes.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2021-10-06 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  9:09 [PATCH] Properly parse invariant &MEM addresses in the GIMPLE FE Richard Biener
2021-10-06 16:25 ` Joseph Myers

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