From f6efea5163e7a321ecda80386ac23488e041ec2b Mon Sep 17 00:00:00 2001 From: Markus Trippelsdorf Date: Wed, 18 Jan 2017 08:40:05 +0000 Subject: [PATCH] Fix PR77489 -- mangling of discriminator >= 1 libiberty: PR c++/77489 * cp-demangle.c (d_discriminator): Handle discriminator >= 10. * testsuite/demangle-expected: Add tests for discriminator. gcc: PR c++/77489 * doc/invoke.texi (fabi-version): Document discriminator mangling. gcc/cp: PR c++/77489 * mangle.c (write_discriminator): Handle discriminator >= 10. From-SVN: r244566 --- gcc/ChangeLog | 5 +++ gcc/cp/ChangeLog | 5 +++ gcc/cp/mangle.c | 11 ++++- gcc/doc/invoke.texi | 4 +- gcc/testsuite/g++.dg/abi/pr77489.C | 63 +++++++++++++++++++++++++++ libiberty/ChangeLog | 6 +++ libiberty/cp-demangle.c | 22 +++++++++- libiberty/testsuite/demangle-expected | 16 +++++++ 8 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/pr77489.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e2ea014ca28..13a7015ccc2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-01-18 Markus Trippelsdorf + + PR c++/77489 + * doc/invoke.texi (fabi-version): Document discriminator mangling. + 2017-01-17 Segher Boessenkool PR target/78875 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d24b2ae23ad..86669ae1371 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-01-18 Markus Trippelsdorf + + PR c++/77489 + * mangle.c (write_discriminator): Handle discriminator >= 10. + 2017-01-17 Nathan Sidwell PR c++/61636 diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 5f2fa35d29e..67ec5c31f17 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,15 @@ write_discriminator (const int discriminator) if (discriminator > 0) { write_char ('_'); + if (abi_version_at_least (11) && discriminator - 1 >= 10) + { + write_char ('_'); + if (abi_warn_or_compat_version_crosses (11)) + G.need_abi_warning = 1; + } write_unsigned_number (discriminator - 1); + if (abi_version_at_least (11) && discriminator - 1 >= 10) + write_char ('_'); } } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index cac3d8bc65e..767c8f42fee 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2252,7 +2252,9 @@ attributes that affect type identity, such as ia32 calling convention attributes (e.g. @samp{stdcall}). Version 11, which first appeared in G++ 7, corrects the mangling of -sizeof... expressions. It also implies +sizeof... expressions. For multiple entities with the same name within +a function, that are declared in different scopes, the mangling now +changes starting with the eighth occurence. It also implies @option{-fnew-inheriting-ctors}. See also @option{-Wabi}. diff --git a/gcc/testsuite/g++.dg/abi/pr77489.C b/gcc/testsuite/g++.dg/abi/pr77489.C new file mode 100644 index 00000000000..13c41cc0acf --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/pr77489.C @@ -0,0 +1,63 @@ +// { 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_9" } } +// { dg-final { scan-assembler "_ZZ3foovE8localVar__10_" } } +// { dg-final { scan-assembler "_ZZ3foovE8localVar__11_" } } diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 20dee7e821d..104907c84c8 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2017-01-18 Markus Trippelsdorf + + PR c++/77489 + * cp-demangle.c (d_discriminator): Handle discriminator >= 10. + * testsuite/demangle-expected: Add tests for discriminator. + 2017-01-04 Jakub Jelinek Update copyright years. diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 15ef3b48785..d84929eca20 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 b65dcd3450e..07e258fe58b 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 +_ZZ3foovE8localVar__12 -- 2.30.2