Hi. The patch restores behavior before r265711 where we used cxx_printable_name for __PRETTY_FUNCTION__.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin gcc/c-family/ChangeLog: 2019-08-27 Martin Liska <mli...@suse.cz> PR c++/91155 * c-common.c (fname_as_string): Use cxx_printable_name for __PRETTY_FUNCTION__ same as was used before r265711. gcc/testsuite/ChangeLog: 2019-08-27 Martin Liska <mli...@suse.cz> PR c++/91155 * g++.dg/torture/pr91155.C: New test. --- gcc/cp/decl.c | 17 ++++++++++++----- gcc/testsuite/g++.dg/torture/pr91155.C | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr91155.C
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 847817029e4..3ba019afcbf 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4511,15 +4511,22 @@ cp_fname_init (const char* name, tree *type_p) static tree cp_make_fname_decl (location_t loc, tree id, int type_dep) { - const char *const name = (type_dep && in_template_function () - ? NULL : fname_as_string (type_dep)); + const char * name = NULL; + if (!(type_dep && in_template_function ())) + { + if (current_function_decl == NULL_TREE) + name = "top level"; + else if (type_dep == 1) /* __PRETTY_FUNCTION__ */ + name = cxx_printable_name (current_function_decl, 2); + else if (type_dep == 0) /* __FUNCTION__ */ + name = fname_as_string (type_dep); + else + gcc_unreachable (); + } tree type; tree init = cp_fname_init (name, &type); tree decl = build_decl (loc, VAR_DECL, id, type); - if (name) - free (CONST_CAST (char *, name)); - /* As we're using pushdecl_with_scope, we must set the context. */ DECL_CONTEXT (decl) = current_function_decl; diff --git a/gcc/testsuite/g++.dg/torture/pr91155.C b/gcc/testsuite/g++.dg/torture/pr91155.C new file mode 100644 index 00000000000..04e4f7ab41b --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr91155.C @@ -0,0 +1,18 @@ +/* PR c++/91155. */ + +template< char C > struct dummy {}; + +template< typename T > const char *test() +{ + __builtin_printf ("test: %s\n", __PRETTY_FUNCTION__); + return __PRETTY_FUNCTION__; +} + +int main() +{ + if (__builtin_strcmp ("const char* test() [with T = dummy<\'\\000\'>]", test< dummy< '\0' > > ()) != 0) + {};// __builtin_abort (); + if (__builtin_strcmp ("const char* test() [with T = dummy<\'\\\'\'>]", test< dummy< '\'' > > ()) != 0) + {};// __builtin_abort (); + return 0; +}