From patchwork Wed Feb 13 15:50:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 220177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 3B6652C0294 for ; Thu, 14 Feb 2013 02:51:19 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1361375480; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=qSn7JvT1TFLwH5XnLg9N vRTBlco=; b=nYxev1LvG6SBt/bv4+nVh0OqdVX1roEn+dqFzcPPRDB+jwMIXYS+ 2zOLKbIxZPav5szUzs4wzxK4YI0sBp08XiqfewPMXOJ4yZgIXAopB555sI6ixbaq /bdOEJoGh5V0Y2zJznQdztMwQg4yKXcYSdO2/4NRr5UDJVlq+HZGgqk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=u2g13HwgrfE+C/mMQVRgB93mtDvdudKaKal0g3dJLf1nd99zt1cNjO14P5/QKH +NeiSXsQFYH9UQLPK57FdsjhMEWlrbsNTNy6d2iW+9bXyoOnzb0SIsY/eqLPkCJN w3zlGlb1aLcQccUfYhif3NaMXTqInaeSEUF7QBQz80qkc=; Received: (qmail 18072 invoked by alias); 13 Feb 2013 15:51:12 -0000 Received: (qmail 18062 invoked by uid 22791); 13 Feb 2013 15:51:11 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Feb 2013 15:50:58 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1DFow89008993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Feb 2013 10:50:58 -0500 Received: from zalov.redhat.com (vpn1-6-84.ams2.redhat.com [10.36.6.84]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1DFourP025358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Feb 2013 10:50:57 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r1DFotA7032029; Wed, 13 Feb 2013 16:50:55 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1DFotTV032028; Wed, 13 Feb 2013 16:50:55 +0100 Date: Wed, 13 Feb 2013 16:50:55 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] For asm "n" and similar constraints use maybe_const_value (PR c++/56302) Message-ID: <20130213155055.GV4385@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi! My SIZEOF_EXPR deferred folding changes regressed some sys/sdt.h macros at -O0, the sizeof in there is no longer folded, so instead of say "n" (-8) we ended up with "n" (-1 * (int) sizeof (void *)) and similar, and as at -O0 we don't really optimize, the asm got rejected. Fixed thusly, constexpr-56302.C is a bonus, something that didn't work before but now works. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-02-13 Jakub Jelinek PR c++/56302 * semantics.c (finish_asm_stmt): If input constraints allow neither register nor memory, try maybe_constant_value to get a constant if possible. * g++.dg/torture/pr56302.C: New test. * g++.dg/cpp0x/constexpr-56302.C: New test. * c-c++-common/pr56302.c: New test. Jakub --- gcc/cp/semantics.c.jj 2013-02-12 19:02:48.000000000 +0100 +++ gcc/cp/semantics.c 2013-02-13 10:04:14.615998647 +0100 @@ -1402,6 +1402,14 @@ finish_asm_stmt (int volatile_p, tree st if (!cxx_mark_addressable (operand)) operand = error_mark_node; } + else if (!allows_reg && !allows_mem) + { + /* If constraint allows neither register nor memory, + try harder to get a constant. */ + tree constop = maybe_constant_value (operand); + if (TREE_CONSTANT (constop)) + operand = constop; + } } else operand = error_mark_node; --- gcc/testsuite/g++.dg/torture/pr56302.C.jj 2013-02-13 10:18:58.785974294 +0100 +++ gcc/testsuite/g++.dg/torture/pr56302.C 2013-02-13 10:22:19.901837358 +0100 @@ -0,0 +1,41 @@ +// PR c++/56302 +// { dg-do compile } + +typedef __SIZE_TYPE__ size_t; +# define STAP_SDT_ARG_CONSTRAINT nor +# define _SDT_STRINGIFY(x) #x +# define _SDT_ARG_CONSTRAINT_STRING(x) _SDT_STRINGIFY(x) +# define _SDT_ARG(n, x) \ + [_SDT_S##n] "n" ((_SDT_ARGSIGNED (x) ? 1 : -1) * (int) _SDT_ARGSIZE (x)), \ + [_SDT_A##n] _SDT_ARG_CONSTRAINT_STRING (STAP_SDT_ARG_CONSTRAINT) (_SDT_ARGVAL (x)) +#define _SDT_ARGARRAY(x) (__builtin_classify_type (x) == 14 \ + || __builtin_classify_type (x) == 5) +# define _SDT_ARGSIGNED(x) (!_SDT_ARGARRAY (x) \ + && __sdt_type<__typeof (x)>::__sdt_signed) +# define _SDT_ARGSIZE(x) (_SDT_ARGARRAY (x) \ + ? sizeof (void *) : sizeof (x)) +# define _SDT_ARGVAL(x) (x) +template +struct __sdt_type +{ + static const bool __sdt_signed = false; +}; +#define __SDT_ALWAYS_SIGNED(T) \ +template<> struct __sdt_type { static const bool __sdt_signed = true; }; +__SDT_ALWAYS_SIGNED(signed char) +__SDT_ALWAYS_SIGNED(short) +__SDT_ALWAYS_SIGNED(int) +__SDT_ALWAYS_SIGNED(long) +__SDT_ALWAYS_SIGNED(long long) +template +struct __sdt_type<__sdt_E[]> : public __sdt_type<__sdt_E *> {}; +template +struct __sdt_type<__sdt_E[__sdt_N]> : public __sdt_type<__sdt_E *> {}; + +struct S { char p[8]; }; + +void +foo (const S &str) +{ + __asm__ __volatile__ ("" : : _SDT_ARG (0, &str)); +} --- gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C 2012-11-17 15:43:17.572007394 +0100 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-56302.C 2013-02-13 10:28:41.462666774 +0100 @@ -0,0 +1,12 @@ +// PR c++/56302 +// { dg-do compile } +// { dg-options "-std=c++11 -O0" } + +constexpr int foo () { return 42; } +constexpr int x = foo () + 2; + +void +bar () +{ + __asm ("" : : "n" (x), "n" (foo () * 7 + x)); +} --- gcc/testsuite/c-c++-common/pr56302.c.jj 2013-02-13 10:10:42.980799956 +0100 +++ gcc/testsuite/c-c++-common/pr56302.c 2013-02-13 10:11:17.906598785 +0100 @@ -0,0 +1,9 @@ +/* PR c++/56302 */ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +void +foo (int x) +{ + __asm__ __volatile__ ("" : : "n" (-1 * (int) sizeof (&x))); +}