From 7fcb278d1e5b18d8c56588ad08bfb5d7a70303e1 Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Sun, 6 Jan 2019 22:26:08 -0800 Subject: [PATCH] Fix demangling template parameter packs (#414) * Fix demangling template parameter packs Clang 4.0.1-10 and gcc 7.3.0 both mangle the function "void add(int)" as "_Z3addIJiEEvDpT_". The template parameter pack is of the form J * E The opening character for a param pack could be either I or J, as libiberty follows [1]. This change simply adds the J case. [1] https://github.com/gcc-mirror/gcc/blob/fbd263526ad105a953fd51d9f7bca2c3f268cf82/libiberty/cp-demangle.c#L3209 --- src/demangle.cc | 3 ++- src/demangle_unittest.txt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/demangle.cc b/src/demangle.cc index d7b3af1..dd26914 100644 --- a/src/demangle.cc +++ b/src/demangle.cc @@ -1097,10 +1097,11 @@ static bool ParseTemplateArgs(State *state) { // ::= // ::= // ::= I * E # argument pack +// ::= J * E # argument pack // ::= X E static bool ParseTemplateArg(State *state) { State copy = *state; - if (ParseOneCharToken(state, 'I') && + if ((ParseOneCharToken(state, 'I') || ParseOneCharToken(state, 'J')) && ZeroOrMore(ParseTemplateArg, state) && ParseOneCharToken(state, 'E')) { return true; diff --git a/src/demangle_unittest.txt b/src/demangle_unittest.txt index 4e23c65..fd6aca0 100644 --- a/src/demangle_unittest.txt +++ b/src/demangle_unittest.txt @@ -135,3 +135,7 @@ _ZlsRSoRKSs operator<<() _ZngILi42EEvN1AIXplT_Li2EEE1TE operator-<>() _ZplR1XS0_ operator+() _Zrm1XS_ operator%() + +# Template argument packs can start with I or J. +_Z3addIIiEEvDpT_ add<>() +_Z3addIJiEEvDpT_ add<>()