From 5fc7fa6910ba9d941e0ee7237282bd6f166f6dac Mon Sep 17 00:00:00 2001 From: aldyh Date: Fri, 28 May 2004 21:56:59 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82381 138bc75d-0d04-0410-961f-82ee72b054a4 --- 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 1fa48e1..a5ed97f 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 4aa17e6..3cf1baa 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 e2c5a97..ce39f6f 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 0000000..ab4c2bc --- /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 0000000..ab4c2bc --- /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.7.4