This patch fixes a few ICEs I encountered when enabling DEBUG_MANGLE. I've also changed dump_substitution_candidates to output the substitution index in base 36, to match the actual mangled name.
OK for trunk? -cary 2013-11-13 Cary Coutant <ccout...@google.com> gcc/ * cp/mangle.c (to_base36): New function. (dump_substitution_candidates): Add checks for NULL. Print substitution index in base 36. commit 5ece725d55f104dd6499ac261380a9c9c4002613 Author: Cary Coutant <ccout...@google.com> Date: Wed Nov 13 09:28:58 2013 -0800 Fix ICEs when DEBUG_MANGLE is enabled. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 202fafc..56c1844 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -301,6 +301,19 @@ decl_is_template_id (const tree decl, tree* const template_info) return 0; } +/* Convert VAL to base 36. */ + +static const char * +to_base36 (int val) +{ + static char buffer[sizeof (HOST_WIDE_INT) * 8 + 1]; + unsigned count; + + count = hwint_to_ascii (number, 36, buffer + sizeof (buffer) - 1, 1); + buffer[sizeof (buffer) - 1] = '\0'; + return buffer + sizeof (buffer) - 1 - count; +} + /* Produce debugging output of current substitution candidates. */ static void @@ -317,12 +330,27 @@ dump_substitution_candidates (void) if (i > 0) fprintf (stderr, " "); if (DECL_P (el)) - name = IDENTIFIER_POINTER (DECL_NAME (el)); + { + if (DECL_NAME (el)) + name = IDENTIFIER_POINTER (DECL_NAME (el)); + } else if (TREE_CODE (el) == TREE_LIST) - name = IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (el))); + { + tree val = TREE_VALUE (el); + if (TREE_CODE (val) == IDENTIFIER_NODE) + name = IDENTIFIER_POINTER (val); + else if (DECL_P (val)) + name = IDENTIFIER_POINTER (DECL_NAME (val)); + } else if (TYPE_NAME (el)) - name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (el))); - fprintf (stderr, " S%d_ = ", i - 1); + { + if (DECL_NAME (TYPE_NAME (el))) + name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (el))); + } + if (i == 0) + fprintf (stderr, " S_ = "); + else + fprintf (stderr, " S%s_ = ", to_base36 (i - 1)); if (TYPE_P (el) && (CP_TYPE_RESTRICT_P (el) || CP_TYPE_VOLATILE_P (el)