From patchwork Wed Jan 11 11:48:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Trippelsdorf X-Patchwork-Id: 713698 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tz6c563tJz9t1P for ; Wed, 11 Jan 2017 22:48:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="PLb31bMH"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=oZue5o/78XbFSnrppLqP7hVlvPYhVGAFPY7OdQuTmbs1o9/gNf ubhlpXmcWlTkzhsEMLK/y6aUIWPJhjFSa6lMi40OEe71mkwcQaroj0u6dki3mK30 7ZfA85WtFmAmdxJFbWftWoEUPyCpblbP3THwPPyi1LGm2PvXObIFPQbfc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=wTjVvRQRydoa2gIzV1d5fzql0bI=; b=PLb31bMH36hdli2D506C ALh5OE52fqufAlXmEOj1qn0TUl/lAMz0wZgMx4kUQqW6DrSfD1xpNgQ+WhaXprDO 8uhTg22s6hA7fRsWVxkNgclYsKzhSRCkFuYQ5E0CxGybzw9K+ukfciti7fXqkIcW 78mNHdp4gE1GBPGSh9XNWKE= Received: (qmail 14814 invoked by alias); 11 Jan 2017 11:48:45 -0000 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 Received: (qmail 14795 invoked by uid 89); 11 Jan 2017 11:48:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ten X-HELO: mail.ud10.udmedia.de Received: from ud10.udmedia.de (HELO mail.ud10.udmedia.de) (194.117.254.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jan 2017 11:48:34 +0000 Received: (qmail 14580 invoked from network); 11 Jan 2017 12:48:30 +0100 Received: from ip5b405f78.dynamic.kabel-deutschland.de (HELO x4) (ud10?360p3@91.64.95.120) by mail.ud10.udmedia.de with ESMTPSA (ECDHE-RSA-AES256-SHA encrypted, authenticated); 11 Jan 2017 12:48:30 +0100 Date: Wed, 11 Jan 2017 12:48:29 +0100 From: Markus Trippelsdorf To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH C++] Fix PR77489 -- mangling of discriminator >= 10 Message-ID: <20170111114829.GA288@x4> MIME-Version: 1.0 Content-Disposition: inline Currently gcc mangles symbols wrongly when the discriminator is greater than ten. The fix is straightforward. The demangler now handles both the old and the new correct mangling. Tested on ppc64le. OK for trunk? Thanks. libiberty: PR c++/77489 * cp-demangle.c (d_discriminator): Handle discriminator >= 10. * testsuite/demangle-expected: Add tests for discriminator. gcc/cp: PR c++/77489 * mangle.c (write_discriminator): Handle discriminator >= 10. +_ZZ3foovE8localVar__12 diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 5f2fa35d29e8..ee75f4a25621 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -1952,7 +1952,8 @@ discriminator_for_string_literal (tree /*function*/, return 0; } -/* := _ +/* := _ # when number < 10 + := __ _ # when number >= 10 The discriminator is used only for the second and later occurrences of the same name within a single function. In this case is @@ -1965,7 +1966,11 @@ write_discriminator (const int discriminator) if (discriminator > 0) { write_char ('_'); + if (abi_version_at_least(11) && discriminator - 1 >= 10) + write_char ('_'); write_unsigned_number (discriminator - 1); + if (abi_version_at_least(11) && discriminator - 1 >= 10) + write_char ('_'); } } diff --git a/gcc/testsuite/g++.dg/abi/pr77489.C b/gcc/testsuite/g++.dg/abi/pr77489.C new file mode 100644 index 000000000000..f640bb6f0676 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/pr77489.C @@ -0,0 +1,62 @@ +// { dg-options -fabi-version=11 } + +extern void bar(int*); + +void foo() +{ + { + static int localVar = 0; + bar(&localVar); + } + { + static int localVar = 1; + bar(&localVar); + } + { + static int localVar = 2; + bar(&localVar); + } + { + static int localVar = 3; + bar(&localVar); + } + { + static int localVar = 4; + bar(&localVar); + } + { + static int localVar = 5; + bar(&localVar); + } + { + static int localVar = 6; + bar(&localVar); + } + { + static int localVar = 7; + bar(&localVar); + } + { + static int localVar = 8; + bar(&localVar); + } + { + static int localVar = 9; + bar(&localVar); + } + { + static int localVar = 10; + bar(&localVar); + } + { + static int localVar = 11; + bar(&localVar); + } + { + static int localVar = 12; + bar(&localVar); + } +} + +// { dg-final { scan-assembler "_ZZ3foovE8localVar__10_" } } +// { dg-final { scan-assembler "_ZZ3foovE8localVar__11_" } } diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 15ef3b48785f..d84929eca20d 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -3609,7 +3609,11 @@ d_local_name (struct d_info *di) } } -/* ::= _ <(non-negative) number> +/* ::= _ # when number < 10 + ::= __ _ # when number >= 10 + + ::= _ # when number >=10 + is also accepted to support gcc versions that wrongly mangled that way. We demangle the discriminator, but we don't print it out. FIXME: We should print it out in verbose mode. */ @@ -3617,14 +3621,28 @@ d_local_name (struct d_info *di) static int d_discriminator (struct d_info *di) { - int discrim; + int discrim, num_underscores = 1; if (d_peek_char (di) != '_') return 1; d_advance (di, 1); + if (d_peek_char (di) == '_') + { + ++num_underscores; + d_advance (di, 1); + } + discrim = d_number (di); if (discrim < 0) return 0; + if (num_underscores > 1 && discrim >= 10) + { + if (d_peek_char (di) == '_') + d_advance (di, 1); + else + return 0; + } + return 1; } diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index b65dcd3450e9..07e258fe58b3 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -4666,3 +4666,19 @@ void eat(int*&, Foo()::{lambda(auto:1 _Z3eatIPiZ3BarIsEvvEUlPsPT_PT0_E0_EvRS3_RS5_ void eat()::{lambda(short*, auto:1*, auto:2*)#2}>(int*&, void Bar()::{lambda(short*, auto:1*, auto:2*)#2}&) + +# PR 77489 +_ZZ3foovE8localVar_9 +foo()::localVar + +_ZZ3foovE8localVar_10 +foo()::localVar + +_ZZ3foovE8localVar__10_ +foo()::localVar + +_ZZ3foovE8localVar__9_ +_ZZ3foovE8localVar__9_ + +_ZZ3foovE8localVar__12