public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR33661 Fix problem with register asm in templates
@ 2015-06-11 13:56 Andreas Krebbel
  2015-06-11 14:05 ` Jakub Jelinek
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Krebbel @ 2015-06-11 13:56 UTC (permalink / raw)
  To: gcc-patches

Hi,

register asm declarations currently don't work when being expanded as
part of a function template.

There appeared to be two problems:

1. When parsing a template function cp_finish_decl returns before the
asmspec is set in the var decl.
2. When expanding the template function the assembler_name is zeroed
out.

Bootstrapped and regtested on x86_64 and s390x.

Ok?

Bye,

-Andreas-

2015-06-11  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	PR C++/33661
	* gcc/cp/decl.c (cp_finish_decl): Set assembler name for register
	asm constructs.
	* gcc/cp/pt.c (tsubst_decl): Do not zero out the assembler name
	for register asm constructs.

2015-06-11  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	PR C++/33661
	* gcc.target/s390/pr33661.cc: New test.
	* gcc.target/s390/s390.exp: Run also tests with .cc suffix.


diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a8cb358..b1eb33d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6536,6 +6536,13 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 
       if (init)
 	DECL_INITIAL (decl) = init;
+
+      /* Set the DECL_ASSEMBLER_NAME for the object.  */
+      if (asmspec && VAR_P (decl) && DECL_REGISTER (decl))
+	{
+	  set_user_assembler_name (decl, asmspec);
+	  DECL_HARD_REGISTER (decl) = 1;
+	}
       return;
     }
 
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a0c5d7c..74ec5dd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11384,7 +11384,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 	cp_apply_type_quals_to_decl (cp_type_quals (type), r);
 	DECL_CONTEXT (r) = ctx;
 	/* Clear out the mangled name and RTL for the instantiation.  */
-	SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
+	if (!VAR_P (r) || !DECL_HARD_REGISTER (r))
+	  SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
 	if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
 	  SET_DECL_RTL (r, NULL);
 	/* The initializer must not be expanded until it is required;
diff --git a/gcc/testsuite/gcc.target/s390/pr33661.cc b/gcc/testsuite/gcc.target/s390/pr33661.cc
new file mode 100644
index 0000000..7070e56
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/pr33661.cc
@@ -0,0 +1,21 @@
+/* PR c++/33661  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+/* { dg-final { scan-assembler "reg: %r3" } } */
+
+typedef unsigned long long int uint64_t;
+
+template < typename T > static inline void
+bar (T c)
+{
+  int a;
+  register unsigned long b __asm__ ("r3") = (unsigned long)&a;
+  __asm__ volatile ("reg: %0" : : "d" (b):);
+}
+
+void
+foo (uint64_t c)
+{
+  bar (c);
+}
diff --git a/gcc/testsuite/gcc.target/s390/s390.exp b/gcc/testsuite/gcc.target/s390/s390.exp
index 0b8f80ed..edef574 100644
--- a/gcc/testsuite/gcc.target/s390/s390.exp
+++ b/gcc/testsuite/gcc.target/s390/s390.exp
@@ -64,7 +64,7 @@ dg-init
 set hotpatch_tests $srcdir/$subdir/hotpatch-\[0-9\]*.c
 
 # Main loop.
-dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\[cS\]] \
+dg-runtest [lsort [prune [glob -nocomplain $srcdir/$subdir/*.\{\[cS\],cc\}] \
 			 $hotpatch_tests]] "" $DEFAULT_CFLAGS
 
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*vector*/*.\[cS\]]] \

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

* Re: [PATCH] PR33661 Fix problem with register asm in templates
  2015-06-11 13:56 [PATCH] PR33661 Fix problem with register asm in templates Andreas Krebbel
@ 2015-06-11 14:05 ` Jakub Jelinek
  2015-06-12  9:03   ` Andreas Krebbel
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2015-06-11 14:05 UTC (permalink / raw)
  To: Andreas Krebbel; +Cc: gcc-patches

Hi!

Just nits, I'll defer the review to a C++ maintainer.

On Thu, Jun 11, 2015 at 03:49:48PM +0200, Andreas Krebbel wrote:

> 2015-06-11  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
> 
> 	PR C++/33661
> 	* gcc/cp/decl.c (cp_finish_decl): Set assembler name for register
> 	asm constructs.
> 	* gcc/cp/pt.c (tsubst_decl): Do not zero out the assembler name
> 	for register asm constructs.

Please avoid gcc/cp/ prefixes in the ChangeLog.

> 2015-06-11  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
> 
> 	PR C++/33661
> 	* gcc.target/s390/pr33661.cc: New test.
> 	* gcc.target/s390/s390.exp: Run also tests with .cc suffix.

This is undesirable, gcc.target/*/ are C tests.  Won't this e.g.
fail miserably if one tests an --enable-languages=c compiler?
The few target specific C++ tests are simply somewhere in the
testsuite/g++.dg/*/ directories, guarded with { target ... }.

But, if this is a generic problem, I'd say testing it only on s390
is insufficient.  I'd think best would be to just do
#if defined(__x86_64__)
  register unsigned long b __asm__ ("r8") = (unsigned long)&a;
  __asm__ volatile ("reg: %0" : : "r" (b));
#elif defined(__i386__)
  register unsigned long b __asm__ ("ecx") = (unsigned long)&a;
  __asm__ volatile ("reg: %0" : : "r" (b));
#elif defined(__s390__)
  register unsigned long b __asm__ ("r2") = (unsigned long)&a;
  __asm__ volatile ("reg: %0" : : "d" (b));
#elif ...
#else
  unsigned long b = (unsigned long)&a;
#endif
and then just have a bunch of
/* { dg-final { scan-assembler "reg: %r8" { target { { x86_64*-*-* i?86-*-* } && lp64 } } } } */
/* { dg-final { scan-assembler "reg: %ecx" { target { { x86_64*-*-* i?86-*-* } && ia32 } } } } */
/* { dg-final { scan-assembler "reg: %r3" { target s390*-*-* } } } */
Covering just a few of the most popular platforms is surely enough.

> +  register unsigned long b __asm__ ("r3") = (unsigned long)&a;
> +  __asm__ volatile ("reg: %0" : : "d" (b):);

The : before ) is unneeded, isn't it?

	Jakub

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

* Re: [PATCH] PR33661 Fix problem with register asm in templates
  2015-06-11 14:05 ` Jakub Jelinek
@ 2015-06-12  9:03   ` Andreas Krebbel
  2015-06-12  9:30     ` Jakub Jelinek
  2015-06-25 13:54     ` [PING] " Andreas Krebbel
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Krebbel @ 2015-06-12  9:03 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

Yes that's better.  I've adjusted the testcase as you proposed and
have tested it on x86_64, ppc, and s390x with -m32(-m31) and -m64.

Bye,

-Andreas-

gcc/cp/

2015-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	PR c++/33661
	* decl.c (cp_finish_decl): Set assembler name for register
	asm constructs.
	* pt.c (tsubst_decl): Do not zero out the assembler name
	for register asm constructs.

gcc/testsuite/

2015-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>

	PR c++/33661
	* g++.dg/pr33661.C: New test.


diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a8cb358..b1eb33d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6536,6 +6536,13 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 
       if (init)
 	DECL_INITIAL (decl) = init;
+
+      /* Set the DECL_ASSEMBLER_NAME for the object.  */
+      if (asmspec && VAR_P (decl) && DECL_REGISTER (decl))
+	{
+	  set_user_assembler_name (decl, asmspec);
+	  DECL_HARD_REGISTER (decl) = 1;
+	}
       return;
     }
 
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a0c5d7c..74ec5dd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11384,7 +11384,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 	cp_apply_type_quals_to_decl (cp_type_quals (type), r);
 	DECL_CONTEXT (r) = ctx;
 	/* Clear out the mangled name and RTL for the instantiation.  */
-	SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
+	if (!VAR_P (r) || !DECL_HARD_REGISTER (r))
+	  SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
 	if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
 	  SET_DECL_RTL (r, NULL);
 	/* The initializer must not be expanded until it is required;
diff --git a/gcc/testsuite/g++.dg/pr33661.C b/gcc/testsuite/g++.dg/pr33661.C
new file mode 100644
index 0000000..2df963f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr33661.C
@@ -0,0 +1,31 @@
+/* PR c++/33661  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+/* { dg-final { scan-assembler "reg: %r8" { target { { x86_64*-*-* i?86-*-* } && lp64 } } } } */
+/* { dg-final { scan-assembler "reg: %ecx" { target { { x86_64*-*-* i?86-*-* } && ia32 } } } } */
+/* { dg-final { scan-assembler "reg: 8" { target { powerpc*-*-* } } } } */
+/* { dg-final { scan-assembler "reg: %r8" { target { s390*-*-* } } } } */
+
+typedef unsigned long long int uint64_t;
+
+template < typename T > static inline void
+bar (T c)
+{
+  int a;
+#if defined(__x86_64__) || defined(__PPC__) || defined(__s390__)
+  register unsigned long b __asm__ ("r8") = (unsigned long)&a;
+  __asm__ volatile ("reg: %0" : : "r" (b));
+#elif defined(__i386__)
+  register unsigned long b __asm__ ("ecx") = (unsigned long)&a;
+  __asm__ volatile ("reg: %0" : : "r" (b));
+#else
+  unsigned long b = (unsigned long)&a;
+#endif
+}
+
+void
+foo (uint64_t c)
+{
+  bar (c);
+}

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

* Re: [PATCH] PR33661 Fix problem with register asm in templates
  2015-06-12  9:03   ` Andreas Krebbel
@ 2015-06-12  9:30     ` Jakub Jelinek
  2015-06-12  9:51       ` Andreas Krebbel
  2015-06-25 13:54     ` [PING] " Andreas Krebbel
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2015-06-12  9:30 UTC (permalink / raw)
  To: Andreas Krebbel, Jason Merrill; +Cc: gcc-patches

On Fri, Jun 12, 2015 at 10:52:56AM +0200, Andreas Krebbel wrote:
> Yes that's better.  I've adjusted the testcase as you proposed and
> have tested it on x86_64, ppc, and s390x with -m32(-m31) and -m64.

As I said earlier, talking just about the testcase, leaving review to Jason.

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr33661.C
> @@ -0,0 +1,31 @@
> +/* PR c++/33661  */
> +
> +/* { dg-do compile } */
> +/* { dg-options "-O1" } */
> +/* { dg-final { scan-assembler "reg: %r8" { target { { x86_64*-*-* i?86-*-* } && lp64 } } } } */
> +/* { dg-final { scan-assembler "reg: %ecx" { target { { x86_64*-*-* i?86-*-* } && ia32 } } } } */
> +/* { dg-final { scan-assembler "reg: 8" { target { powerpc*-*-* } } } } */

Looks mostly good, just wonder about the powerpc scan-assembler.
Shouldn't that be "reg: (%r)?8" instead?  I think powerpc has -mregnames
option, dunno if some target doesn't even use it by default.

	Jakub

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

* Re: [PATCH] PR33661 Fix problem with register asm in templates
  2015-06-12  9:30     ` Jakub Jelinek
@ 2015-06-12  9:51       ` Andreas Krebbel
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Krebbel @ 2015-06-12  9:51 UTC (permalink / raw)
  To: Jakub Jelinek, Jason Merrill; +Cc: gcc-patches

On 06/12/2015 11:24 AM, Jakub Jelinek wrote:
> Looks mostly good, just wonder about the powerpc scan-assembler.
> Shouldn't that be "reg: (%r)?8" instead?  I think powerpc has -mregnames
> option, dunno if some target doesn't even use it by default.

Good catch. I'll change that.

-Andreas-


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

* [PING] PR33661 Fix problem with register asm in templates
  2015-06-12  9:03   ` Andreas Krebbel
  2015-06-12  9:30     ` Jakub Jelinek
@ 2015-06-25 13:54     ` Andreas Krebbel
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Krebbel @ 2015-06-25 13:54 UTC (permalink / raw)
  To: jason; +Cc: gcc-patches

On 06/12/2015 10:52 AM, Andreas Krebbel wrote:
> Yes that's better.  I've adjusted the testcase as you proposed and
> have tested it on x86_64, ppc, and s390x with -m32(-m31) and -m64.
> 
> Bye,
> 
> -Andreas-
> 
> gcc/cp/
> 
> 2015-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
> 
> 	PR c++/33661
> 	* decl.c (cp_finish_decl): Set assembler name for register
> 	asm constructs.
> 	* pt.c (tsubst_decl): Do not zero out the assembler name
> 	for register asm constructs.
> 
> gcc/testsuite/
> 
> 2015-06-12  Andreas Krebbel  <krebbel@linux.vnet.ibm.com>
> 
> 	PR c++/33661
> 	* g++.dg/pr33661.C: New test.
> 
> 
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index a8cb358..b1eb33d 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -6536,6 +6536,13 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
> 
>        if (init)
>  	DECL_INITIAL (decl) = init;
> +
> +      /* Set the DECL_ASSEMBLER_NAME for the object.  */
> +      if (asmspec && VAR_P (decl) && DECL_REGISTER (decl))
> +	{
> +	  set_user_assembler_name (decl, asmspec);
> +	  DECL_HARD_REGISTER (decl) = 1;
> +	}
>        return;
>      }
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index a0c5d7c..74ec5dd 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -11384,7 +11384,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
>  	cp_apply_type_quals_to_decl (cp_type_quals (type), r);
>  	DECL_CONTEXT (r) = ctx;
>  	/* Clear out the mangled name and RTL for the instantiation.  */
> -	SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
> +	if (!VAR_P (r) || !DECL_HARD_REGISTER (r))
> +	  SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
>  	if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
>  	  SET_DECL_RTL (r, NULL);
>  	/* The initializer must not be expanded until it is required;
> diff --git a/gcc/testsuite/g++.dg/pr33661.C b/gcc/testsuite/g++.dg/pr33661.C
> new file mode 100644
> index 0000000..2df963f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr33661.C
> @@ -0,0 +1,31 @@
> +/* PR c++/33661  */
> +
> +/* { dg-do compile } */
> +/* { dg-options "-O1" } */
> +/* { dg-final { scan-assembler "reg: %r8" { target { { x86_64*-*-* i?86-*-* } && lp64 } } } } */
> +/* { dg-final { scan-assembler "reg: %ecx" { target { { x86_64*-*-* i?86-*-* } && ia32 } } } } */
> +/* { dg-final { scan-assembler "reg: 8" { target { powerpc*-*-* } } } } */
> +/* { dg-final { scan-assembler "reg: %r8" { target { s390*-*-* } } } } */
> +
> +typedef unsigned long long int uint64_t;
> +
> +template < typename T > static inline void
> +bar (T c)
> +{
> +  int a;
> +#if defined(__x86_64__) || defined(__PPC__) || defined(__s390__)
> +  register unsigned long b __asm__ ("r8") = (unsigned long)&a;
> +  __asm__ volatile ("reg: %0" : : "r" (b));
> +#elif defined(__i386__)
> +  register unsigned long b __asm__ ("ecx") = (unsigned long)&a;
> +  __asm__ volatile ("reg: %0" : : "r" (b));
> +#else
> +  unsigned long b = (unsigned long)&a;
> +#endif
> +}
> +
> +void
> +foo (uint64_t c)
> +{
> +  bar (c);
> +}
> 

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

end of thread, other threads:[~2015-06-25 13:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11 13:56 [PATCH] PR33661 Fix problem with register asm in templates Andreas Krebbel
2015-06-11 14:05 ` Jakub Jelinek
2015-06-12  9:03   ` Andreas Krebbel
2015-06-12  9:30     ` Jakub Jelinek
2015-06-12  9:51       ` Andreas Krebbel
2015-06-25 13:54     ` [PING] " Andreas Krebbel

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