From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22414 invoked by alias); 11 Jun 2015 13:49:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 22394 invoked by uid 89); 11 Jun 2015 13:49:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: e06smtp16.uk.ibm.com Received: from e06smtp16.uk.ibm.com (HELO e06smtp16.uk.ibm.com) (195.75.94.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 11 Jun 2015 13:49:54 +0000 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Jun 2015 14:49:51 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 11 Jun 2015 14:49:50 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id A67011B08069 for ; Thu, 11 Jun 2015 14:50:48 +0100 (BST) Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t5BDno6S24314012 for ; Thu, 11 Jun 2015 13:49:50 GMT Received: from d06av11.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t5BDnnE3010069 for ; Thu, 11 Jun 2015 07:49:49 -0600 Received: from bart (dyn-9-152-212-139.boeblingen.de.ibm.com [9.152.212.139]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with SMTP id t5BDnmU3010004 for ; Thu, 11 Jun 2015 07:49:48 -0600 Received: by bart (sSMTP sendmail emulation); Thu, 11 Jun 2015 15:49:48 +0200 Date: Thu, 11 Jun 2015 13:56:00 -0000 From: Andreas Krebbel To: gcc-patches@gcc.gnu.org Subject: [PATCH] PR33661 Fix problem with register asm in templates Message-ID: <20150611134948.GA14778@maggie> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15061113-0025-0000-0000-0000058CF56E X-IsSubscribed: yes X-SW-Source: 2015-06/txt/msg00839.txt.bz2 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 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 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\]]] \