This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR33661 Fix problem with register asm in templates
- From: Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 11 Jun 2015 15:49:48 +0200
- Subject: [PATCH] PR33661 Fix problem with register asm in templates
- Authentication-results: sourceware.org; auth=none
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\]]] \