This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR33661 Fix problem with register asm in templates


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);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]