From patchwork Mon Jun 20 14:27:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 101136 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 92812B6F75 for ; Tue, 21 Jun 2011 00:27:48 +1000 (EST) Received: (qmail 1903 invoked by alias); 20 Jun 2011 14:27:45 -0000 Received: (qmail 1889 invoked by uid 22791); 20 Jun 2011 14:27:44 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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, 20 Jun 2011 14:27:27 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5KERRww017303 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 20 Jun 2011 10:27:27 -0400 Received: from [127.0.0.1] ([10.3.113.2]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5KERRCH001031 for ; Mon, 20 Jun 2011 10:27:27 -0400 Message-ID: <4DFF58CE.7000006@redhat.com> Date: Mon, 20 Jun 2011 10:27:26 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: libiberty PATCH for c++/37089 (wrong demangling of reference to reference) 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 C++0x specifies that a reference to reference produced by template argument substitution collapses to a single reference. Tested x86_64-pc-linux-gnu, applying to trunk. commit b66f8ede160d3f3375d7cd68988f3d498d51cc41 Author: Jason Merrill Date: Sun Jun 19 10:01:02 2011 -0400 PR c++/37089 * cp-demangle.c (d_print_comp): Handle reference smashing. diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 3fc5266..d664e5f 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -3554,6 +3554,10 @@ static void d_print_comp (struct d_print_info *dpi, int options, const struct demangle_component *dc) { + /* Magic variable to let reference smashing skip over the next modifier + without needing to modify *dc. */ + const struct demangle_component *mod_inner = NULL; + if (dc == NULL) { d_print_error (dpi); @@ -3869,16 +3873,37 @@ d_print_comp (struct d_print_info *dpi, int options, } } } + goto modifier; + + case DEMANGLE_COMPONENT_REFERENCE: + case DEMANGLE_COMPONENT_RVALUE_REFERENCE: + { + /* Handle reference smashing: & + && = &. */ + const struct demangle_component *sub = d_left (dc); + if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM) + { + struct demangle_component *a = d_lookup_template_argument (dpi, sub); + if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) + a = d_index_template_argument (a, dpi->pack_index); + sub = a; + } + + if (sub->type == DEMANGLE_COMPONENT_REFERENCE + || sub->type == dc->type) + dc = sub; + else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE) + mod_inner = d_left (sub); + } /* Fall through. */ + case DEMANGLE_COMPONENT_RESTRICT_THIS: case DEMANGLE_COMPONENT_VOLATILE_THIS: case DEMANGLE_COMPONENT_CONST_THIS: case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: case DEMANGLE_COMPONENT_POINTER: - case DEMANGLE_COMPONENT_REFERENCE: - case DEMANGLE_COMPONENT_RVALUE_REFERENCE: case DEMANGLE_COMPONENT_COMPLEX: case DEMANGLE_COMPONENT_IMAGINARY: + modifier: { /* We keep a list of modifiers on the stack. */ struct d_print_mod dpm; @@ -3889,7 +3914,10 @@ d_print_comp (struct d_print_info *dpi, int options, dpm.printed = 0; dpm.templates = dpi->templates; - d_print_comp (dpi, options, d_left (dc)); + if (!mod_inner) + mod_inner = d_left (dc); + + d_print_comp (dpi, options, mod_inner); /* If the modifier didn't get printed by the type, print it now. */ diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index c94eb3c..bbd418c 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3957,6 +3957,9 @@ decltype (({parm#1}.(operator-))()) h(A) _Z1fDn f(decltype(nullptr)) --format=gnu-v3 +_Z1fIRiEvOT_b +void f(int&, bool) +--format=gnu-v3 _ZN5aaaaa6bbbbbb5cccccIN23ddddddddddddddddddddddd3eeeENS2_4ffff16ggggggggggggggggENS0_9hhhhhhhhhES6_S6_S6_S6_S6_S6_S6_EE aaaaa::bbbbbb::ccccc --format=gnu-v3 @@ -4118,4 +4121,4 @@ DFA # http://sourceware.org/bugzilla/show_bug.cgi?id=11572 --format=auto _ZN3Psi7VariantIIcPKcEE5visitIIRZN11VariantTest9TestVisit11test_methodEvEUlS2_E0_RZNS6_11test_methodEvEUlcE1_RZNS6_11test_methodEvEUlNS_4NoneEE_EEENS_13VariantDetail19SelectVisitorResultIIDpT_EE4typeEDpOSG_ -Psi::VariantDetail::SelectVisitorResult::type Psi::Variant::visit((VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&&&)...) +Psi::VariantDetail::SelectVisitorResult::type Psi::Variant::visit((VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&)...)