Message ID | 20150612085256.GA29958@maggie |
---|---|
State | New |
Headers | show |
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
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-
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); > +} >
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); +}