diff mbox series

report message for operator %a on unaddressible operand

Message ID 20240515023447.350404-1-guojiufu@linux.ibm.com
State New
Headers show
Series report message for operator %a on unaddressible operand | expand

Commit Message

Jiufu Guo May 15, 2024, 2:34 a.m. UTC
Hi,

For PR96866, when printing asm code for modifier "%a", an addressable
operand is required.  While the constraint "X" allow any kind of
operand even which is hard to get the address directly. e.g. extern
symbol whose address is in TOC.
An error message would be reported to indicate the invalid asm operand.

Bootstrap&regtest pass on ppc64{,le}.
Is this ok for trunk?

BR,
Jeff(Jiufu Guo)

	PR target/96866

gcc/ChangeLog:

	* config/rs6000/rs6000.cc (print_operand_address):

gcc/testsuite/ChangeLog:

	* gcc.target/powerpc/pr96866-1.c: New test.
	* gcc.target/powerpc/pr96866-2.c: New test.

---
 gcc/config/rs6000/rs6000.cc                  |  6 +++++-
 gcc/testsuite/gcc.target/powerpc/pr96866-1.c | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/pr96866-2.c | 13 +++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr96866-1.c
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr96866-2.c

Comments

Jiufu Guo May 15, 2024, 2:41 a.m. UTC | #1
Hi,

Sorry for missing word "V2". According to previous comments,
this version updates:
1. using different 'tests' for the invalid case, and put the msg
to a better and safer possition.
2. refine the words of the message.
3. updates the test case a little for comments.

BR,
Jeff(Jiufu) Guo

Jiufu Guo <guojiufu@linux.ibm.com> writes:

> Hi,
>
> For PR96866, when printing asm code for modifier "%a", an addressable
> operand is required.  While the constraint "X" allow any kind of
> operand even which is hard to get the address directly. e.g. extern
> symbol whose address is in TOC.
> An error message would be reported to indicate the invalid asm operand.
>
> Bootstrap&regtest pass on ppc64{,le}.
> Is this ok for trunk?
>
> BR,
> Jeff(Jiufu Guo)
>
> 	PR target/96866
>
> gcc/ChangeLog:
>
> 	* config/rs6000/rs6000.cc (print_operand_address):
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/powerpc/pr96866-1.c: New test.
> 	* gcc.target/powerpc/pr96866-2.c: New test.
>
> ---
>  gcc/config/rs6000/rs6000.cc                  |  6 +++++-
>  gcc/testsuite/gcc.target/powerpc/pr96866-1.c | 18 ++++++++++++++++++
>  gcc/testsuite/gcc.target/powerpc/pr96866-2.c | 13 +++++++++++++
>  3 files changed, 36 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/powerpc/pr96866-1.c
>  create mode 100644 gcc/testsuite/gcc.target/powerpc/pr96866-2.c
>
> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> index 117999613d8..38b2806f209 100644
> --- a/gcc/config/rs6000/rs6000.cc
> +++ b/gcc/config/rs6000/rs6000.cc
> @@ -14664,7 +14664,11 @@ print_operand_address (FILE *file, rtx x)
>  	fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
>  		 reg_names[SMALL_DATA_REG]);
>        else
> -	gcc_assert (!TARGET_TOC);
> +	{
> +	  /* Do not support getting address directly from TOC.  */
> +	  if (TARGET_TOC)
> +	    output_operand_lossage ("%%a requires a memory reference operand");
> +	}
>      }
>    else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
>  	   && REG_P (XEXP (x, 1)))
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr96866-1.c b/gcc/testsuite/gcc.target/powerpc/pr96866-1.c
> new file mode 100644
> index 00000000000..d5ccb9c2c49
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr96866-1.c
> @@ -0,0 +1,18 @@
> +/* The "%a" modifier can not print the extern symbol through TOC under
> +   -fPIC, even the symbol is propgated for "X" constraint under -O2. */
> +/* { dg-options "-fPIC -O2" } */
> +
> +/* It's to verify no ICE here, ignore error messages about invalid 'asm'.  */
> +/* { dg-excess-errors "pr96866-1.c" } */
> +
> +int x[2];
> +
> +int __attribute__ ((noipa))
> +f1 (void)
> +{
> +  int n;
> +  int *p = x;
> +  *p++;
> +  __asm__ volatile("ld %0, %a1" : "=r"(n) : "X"(p));
> +  return n;
> +}
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr96866-2.c b/gcc/testsuite/gcc.target/powerpc/pr96866-2.c
> new file mode 100644
> index 00000000000..c0639d260ea
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr96866-2.c
> @@ -0,0 +1,13 @@
> +/* The "%a" modifier can not handle the extern symbol through TOC
> +   for "X" constraint under -fPIC. */
> +/* { dg-options "-fPIC -O2" } */
> +
> +/* It's to verify no ICE here, ignore error messages about invalid 'asm'.  */
> +/* { dg-excess-errors "pr96866-2.c" } */
> +
> +void
> +f (void)
> +{
> +  extern int x;
> +  __asm__ volatile("#%a0" ::"X"(&x));
> +}
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 117999613d8..38b2806f209 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -14664,7 +14664,11 @@  print_operand_address (FILE *file, rtx x)
 	fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
 		 reg_names[SMALL_DATA_REG]);
       else
-	gcc_assert (!TARGET_TOC);
+	{
+	  /* Do not support getting address directly from TOC.  */
+	  if (TARGET_TOC)
+	    output_operand_lossage ("%%a requires a memory reference operand");
+	}
     }
   else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
 	   && REG_P (XEXP (x, 1)))
diff --git a/gcc/testsuite/gcc.target/powerpc/pr96866-1.c b/gcc/testsuite/gcc.target/powerpc/pr96866-1.c
new file mode 100644
index 00000000000..d5ccb9c2c49
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr96866-1.c
@@ -0,0 +1,18 @@ 
+/* The "%a" modifier can not print the extern symbol through TOC under
+   -fPIC, even the symbol is propgated for "X" constraint under -O2. */
+/* { dg-options "-fPIC -O2" } */
+
+/* It's to verify no ICE here, ignore error messages about invalid 'asm'.  */
+/* { dg-excess-errors "pr96866-1.c" } */
+
+int x[2];
+
+int __attribute__ ((noipa))
+f1 (void)
+{
+  int n;
+  int *p = x;
+  *p++;
+  __asm__ volatile("ld %0, %a1" : "=r"(n) : "X"(p));
+  return n;
+}
diff --git a/gcc/testsuite/gcc.target/powerpc/pr96866-2.c b/gcc/testsuite/gcc.target/powerpc/pr96866-2.c
new file mode 100644
index 00000000000..c0639d260ea
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr96866-2.c
@@ -0,0 +1,13 @@ 
+/* The "%a" modifier can not handle the extern symbol through TOC
+   for "X" constraint under -fPIC. */
+/* { dg-options "-fPIC -O2" } */
+
+/* It's to verify no ICE here, ignore error messages about invalid 'asm'.  */
+/* { dg-excess-errors "pr96866-2.c" } */
+
+void
+f (void)
+{
+  extern int x;
+  __asm__ volatile("#%a0" ::"X"(&x));
+}