From patchwork Mon Mar 7 20:08:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 85796 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 772BBB70FF for ; Tue, 8 Mar 2011 07:09:05 +1100 (EST) Received: (qmail 27710 invoked by alias); 7 Mar 2011 20:09:03 -0000 Received: (qmail 27702 invoked by uid 22791); 7 Mar 2011 20:09:01 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CF, T_RP_MATCHES_RCVD 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; Mon, 07 Mar 2011 20:08:52 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p27K8o0t027750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Mar 2011 15:08:50 -0500 Received: from [127.0.0.1] (ovpn-113-31.phx2.redhat.com [10.3.113.31]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p27K8nsO009335 for ; Mon, 7 Mar 2011 15:08:50 -0500 Message-ID: <4D753B51.1040208@redhat.com> Date: Mon, 07 Mar 2011 15:08:49 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/48008 (mangling clash with -fabi-version=5) 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 My patch from last July to avoid mangling attribute const/volatile as qualifiers on the type had the unfortunate effect of also omitting const/volatile function-cv-quals on plain function types, which can occur as template arguments. This patch fixes that by stripping the attribute-derived qualifiers on pointer/reference-to-function types, where the function-cv-quals cannot occur. Tested x86_64-pc-linux-gnu, applied to trunk. commit 5f2add86f317fdc58ca590401baf873908043672 Author: Jason Merrill Date: Mon Mar 7 13:03:12 2011 -0500 PR c++/48008 * mangle.c (write_type): Strip cv-quals from FUNCTION_TYPE here. (write_CV_qualifiers_for_type): Not here. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 0297a2a..c46ba30 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -1880,16 +1880,25 @@ write_type (tree type) break; case POINTER_TYPE: - write_char ('P'); - write_type (TREE_TYPE (type)); - break; - case REFERENCE_TYPE: - if (TYPE_REF_IS_RVALUE (type)) - write_char('O'); + if (TREE_CODE (type) == POINTER_TYPE) + write_char ('P'); + else if (TYPE_REF_IS_RVALUE (type)) + write_char ('O'); else write_char ('R'); - write_type (TREE_TYPE (type)); + { + tree target = TREE_TYPE (type); + /* Attribute const/noreturn are not reflected in mangling. + We strip them here rather than at a lower level because + a typedef or template argument can have function type + with function-cv-quals (that use the same representation), + but you can't have a pointer/reference to such a type. */ + if (abi_version_at_least (5) + && TREE_CODE (target) == FUNCTION_TYPE) + target = build_qualified_type (target, TYPE_UNQUALIFIED); + write_type (target); + } break; case TEMPLATE_TYPE_PARM: @@ -2017,12 +2026,6 @@ write_CV_qualifiers_for_type (const tree type) array. */ cp_cv_quals quals = TYPE_QUALS (type); - /* Attribute const/noreturn are not reflected in mangling. */ - if (abi_version_at_least (5) - && (TREE_CODE (type) == FUNCTION_TYPE - || TREE_CODE (type) == METHOD_TYPE)) - return 0; - if (quals & TYPE_QUAL_RESTRICT) { write_char ('r'); diff --git a/gcc/testsuite/g++.dg/abi/mangle46.C b/gcc/testsuite/g++.dg/abi/mangle46.C new file mode 100644 index 0000000..fddc88d --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle46.C @@ -0,0 +1,15 @@ +// PR c++/48008 +// { dg-options -fabi-version=5 } +// Test that we retain function-cv-quals in template argument mangling. + +template +struct A +{ }; + +typedef void cfn(int) const; +typedef void fn(int); + +// { dg-final { scan-assembler "_Z1f1AIFviEE" } } +void f(A) { } +// { dg-final { scan-assembler "_Z1f1AIKFviEE" } } +void f(A) { }