From patchwork Thu Feb 14 22:37:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 220536 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 B62CA2C007C for ; Fri, 15 Feb 2013 09:37:26 +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=1361486248; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=l8drZoQ ctJ8jB7tC+HkNm1Z5TXs=; b=CPxbpoWv8ibr+otYeZraucbbDB50UkfbjBaeD6l QlG9WVNItdvxmjgfCJ5iLy2HAuOUQjLZRSb35ZQDfzB7UiucaAnbiTuMxAchOtjV tbBYzlWcvhPkB5yswjV6890M7FB6UabxGkYyT68nUlYORc0uiohhcNyoWgzArEQL 4ZGM= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cRnYJtQQrMhqLbt/65FovqeTLuOWrNPFKcXL3VeUzbJR5oTlyrlI1A2Il8cnPt v+mpr7aSxOB1pikIk7J1qi7XkYtMqeRgP4TvZ1Gv0E4tMV9jfcxnONrgK0YsxkpL cpbO0pjaF/uKYBXBDSdpkvOw+FeBd1MWB1TVrTkxP5XAU=; Received: (qmail 15297 invoked by alias); 14 Feb 2013 22:37:17 -0000 Received: (qmail 15223 invoked by uid 22791); 14 Feb 2013 22:37:16 -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; Thu, 14 Feb 2013 22:37:04 +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 r1EMb42x004719 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Feb 2013 17:37:04 -0500 Received: from [10.3.113.52] (ovpn-113-52.phx2.redhat.com [10.3.113.52]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1EMb13r020518 for ; Thu, 14 Feb 2013 17:37:03 -0500 Message-ID: <511D670D.6020307@redhat.com> Date: Thu, 14 Feb 2013 17:37:01 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55223 (ICE with lambda in default argument scope) 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 In this PR, when we go to substitute into LAMBDA_EXPR_EXTRA_SCOPE, we look for a local specialization of the parameter 'f', but there isn't one because we aren't in a function body. For this case, unlike uses in a trailing-return-type, we really need to look up the parameter in the function parameter list in order to get the right mangling. While I was looking at this I noticed that the names weren't demangling, which turned out to be bugs in both the mangler and demangler, which I've also fixed. Tested x86_64-pc-linux-gnu, applying to trunk. commit 687e8c127536a8c208431d1786319ea6efda8637 Author: Jason Merrill Date: Thu Feb 14 10:31:38 2013 -0500 PR c++/55223 gcc/cp/ * pt.c (tsubst_copy_and_build) [LAMBDA_EXPR]: Fix handling of default argument scope. * mangle.c (write_name): Likewise. libiberty/ * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_DEFAULT_ARG. (d_print_comp): Likewise. diff --git a/gcc/common.opt b/gcc/common.opt index b6592e0..3c7b415 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -785,7 +785,8 @@ Driver Undocumented ; argument. ; First selectable in G++ 4.7. ; -; 7: The version of the ABI that treats nullptr_t as a builtin type. +; 7: The version of the ABI that treats nullptr_t as a builtin type and +; corrects the mangling of lambdas in default argument scope. ; First selectable in G++ 4.8. ; Additional positive integers will be assigned as new versions of ; the ABI become the default version of the ABI. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index f6b3443..a48d476 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -802,7 +802,10 @@ write_name (tree decl, const int ignore_local_scope) if (context == NULL || context == global_namespace || DECL_NAMESPACE_STD_P (context) - || (ignore_local_scope && TREE_CODE (context) == FUNCTION_DECL)) + || (ignore_local_scope + && (TREE_CODE (context) == FUNCTION_DECL + || (abi_version_at_least (7) + && TREE_CODE (context) == PARM_DECL)))) { tree template_info; /* Is this a template instance? */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bd44fde..aa868a4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14444,8 +14444,20 @@ tsubst_copy_and_build (tree t, than build a new one. */ tree scope = LAMBDA_EXPR_EXTRA_SCOPE (t); if (scope && TREE_CODE (scope) == FUNCTION_DECL) - scope = tsubst (LAMBDA_EXPR_EXTRA_SCOPE (t), args, - complain, in_decl); + scope = tsubst (scope, args, complain, in_decl); + else if (scope && TREE_CODE (scope) == PARM_DECL) + { + /* Look up the parameter we want directly, as tsubst_copy + doesn't do what we need. */ + tree fn = tsubst (DECL_CONTEXT (scope), args, complain, in_decl); + tree parm = FUNCTION_FIRST_USER_PARM (fn); + while (DECL_PARM_INDEX (parm) != DECL_PARM_INDEX (scope)) + parm = DECL_CHAIN (parm); + scope = parm; + /* FIXME Work around the parm not having DECL_CONTEXT set. */ + if (DECL_CONTEXT (scope) == NULL_TREE) + DECL_CONTEXT (scope) = fn; + } else scope = RECUR (scope); LAMBDA_EXPR_EXTRA_SCOPE (r) = scope; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg3.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg3.C new file mode 100644 index 0000000..f02fb29 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-defarg3.C @@ -0,0 +1,18 @@ +// PR c++/55223 +// { dg-options "-std=c++11 -fabi-version=0" } +// { dg-final { scan-assembler "_ZN8functionC1IZN1CIiE4testES_Ed_UliE_EET_" } } + +struct function +{ + template function(U u) { } +}; + +template struct C +{ + static T test(function f = [](int i){return i;}) { } +}; + +int main() +{ + C::test(); +} diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 913d4bf..39be031 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -707,6 +707,14 @@ d_dump (struct demangle_component *dc, int indent) case DEMANGLE_COMPONENT_TLS_WRAPPER: printf ("tls wrapper function\n"); break; + case DEMANGLE_COMPONENT_DEFAULT_ARG: + printf ("default argument %d\n", dc->u.s_unary_num.num); + d_dump (dc->u.s_unary_num.sub, indent+2); + return; + case DEMANGLE_COMPONENT_LAMBDA: + printf ("lambda %d\n", dc->u.s_unary_num.num); + d_dump (dc->u.s_unary_num.sub, indent+2); + return; } d_dump (d_left (dc), indent + 2); @@ -3168,6 +3176,7 @@ d_expr_primary (struct d_info *di) /* ::= Z <(function) encoding> E <(entity) name> [] ::= Z <(function) encoding> E s [] + ::= Z <(function) encoding> E d [ number>] _ */ static struct demangle_component * @@ -3869,7 +3878,17 @@ d_print_comp (struct d_print_info *dpi, int options, d_append_string (dpi, "::"); else d_append_char (dpi, '.'); - d_print_comp (dpi, options, d_right (dc)); + { + struct demangle_component *local_name = d_right (dc); + if (local_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG) + { + d_append_string (dpi, "{default arg#"); + d_append_num (dpi, local_name->u.s_unary_num.num + 1); + d_append_string (dpi, "}::"); + local_name = local_name->u.s_unary_num.sub; + } + d_print_comp (dpi, options, local_name); + } return; case DEMANGLE_COMPONENT_TYPED_NAME: diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 5b41b03..17eacaa 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3951,6 +3951,9 @@ S::f(int, int)::{default arg#2}::{lambda()#2}::operator()() const _ZNK1SIiE1xMUlvE1_clEv S::x::{lambda()#3}::operator()() const --format=gnu-v3 +_ZN8functionC1IZN1CIiE4testES_Ed_UliE_EET_ +function::function::test(function)::{default arg#1}::{lambda(int)#1}>(C::test(function)::{default arg#1}::{lambda(int)#1}) +--format=gnu-v3 _Z1fN1SUt_E f(S::{unnamed type#1}) --format=gnu-v3