From 0d0bc03606fc5c4d655130b9f060b018412187cf Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Fri, 28 May 2004 21:56:59 +0000 Subject: [PATCH] function.cc: New. * testsuite/g++.dg/charset/function.cc: New. * testsuite/gcc.dg/charset/function.c: New. * c-decl.c (c_make_fname_decl): Free return value from fname_as_string. * cp/decl.c (cp_make_fname_decl): Free return value from fname_as_string. * c-common.c (fname_as_string): Translate if necessary. From-SVN: r82381 --- gcc/ChangeLog | 14 ++++++++++++++ gcc/c-common.c | 24 ++++++++++++++++++++++-- gcc/c-decl.c | 1 + gcc/testsuite/g++.dg/charset/function.cc | 10 ++++++++++ gcc/testsuite/gcc.dg/charset/function.c | 10 ++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/charset/function.cc create mode 100644 gcc/testsuite/gcc.dg/charset/function.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1fa48e1d06e..a5ed97f3dc3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2004-05-28 Aldy Hernandez + + * testsuite/g++.dg/charset/function.cc: New. + + * testsuite/gcc.dg/charset/function.c: New. + + * c-decl.c (c_make_fname_decl): Free return value from + fname_as_string. + + * cp/decl.c (cp_make_fname_decl): Free return value from + fname_as_string. + + * c-common.c (fname_as_string): Translate if necessary. + 2004-05-28 Geoffrey Keating * stringpool.c: Add comments to PCH saving/restoring routines. diff --git a/gcc/c-common.c b/gcc/c-common.c index 4aa17e622dc..3cf1baa7a8e 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1086,12 +1086,13 @@ finish_fname_decls (void) } /* Return the text name of the current function, suitably prettified - by PRETTY_P. */ + by PRETTY_P. Return string must be freed by caller. */ const char * fname_as_string (int pretty_p) { const char *name = "top level"; + char *namep; int vrb = 2; if (! pretty_p) @@ -1103,7 +1104,26 @@ fname_as_string (int pretty_p) if (current_function_decl) name = lang_hooks.decl_printable_name (current_function_decl, vrb); - return name; + if (c_lex_string_translate) + { + int len = strlen (name) + 3; /* Two for '"'s. One for NULL. */ + cpp_string cstr = { 0, 0 }, strname; + + namep = xmalloc (len); + snprintf (namep, len, "\"%s\"", name); + strname.text = (unsigned char *) namep; + strname.len = len - 1; + + if (cpp_interpret_string (parse_in, &strname, 1, &cstr, false)) + return (char *) cstr.text; + } + else + { + namep = (char *) xcalloc (strlen (name) + 1, sizeof (char)); + namep = xstrdup (name); + } + + return namep; } /* Return the VAR_DECL for a const char array naming the current diff --git a/gcc/c-decl.c b/gcc/c-decl.c index e2c5a97a7f7..ce39f6f54f4 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -2362,6 +2362,7 @@ c_make_fname_decl (tree id, int type_dep) DECL_ARTIFICIAL (decl) = 1; init = build_string (length + 1, name); + free ((char *) name); TREE_TYPE (init) = type; DECL_INITIAL (decl) = init; diff --git a/gcc/testsuite/g++.dg/charset/function.cc b/gcc/testsuite/g++.dg/charset/function.cc new file mode 100644 index 00000000000..ab4c2bcba0e --- /dev/null +++ b/gcc/testsuite/g++.dg/charset/function.cc @@ -0,0 +1,10 @@ +/* { dg-do compile } + { dg-require-iconv "IBM-1047" } + { dg-final { scan-assembler-not "\"foobar\"" } } */ + +const char *str; + +void foobar (void) +{ + str = __FUNCTION__; +} diff --git a/gcc/testsuite/gcc.dg/charset/function.c b/gcc/testsuite/gcc.dg/charset/function.c new file mode 100644 index 00000000000..ab4c2bcba0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/charset/function.c @@ -0,0 +1,10 @@ +/* { dg-do compile } + { dg-require-iconv "IBM-1047" } + { dg-final { scan-assembler-not "\"foobar\"" } } */ + +const char *str; + +void foobar (void) +{ + str = __FUNCTION__; +} -- 2.30.2