Commit 0d0bc036 by Aldy Hernandez Committed by Aldy Hernandez

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
parent 4bb4ae96
2004-05-28 Aldy Hernandez <aldyh@redhat.com>
* 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 <geoffk@apple.com> 2004-05-28 Geoffrey Keating <geoffk@apple.com>
* stringpool.c: Add comments to PCH saving/restoring routines. * stringpool.c: Add comments to PCH saving/restoring routines.
......
...@@ -1086,12 +1086,13 @@ finish_fname_decls (void) ...@@ -1086,12 +1086,13 @@ finish_fname_decls (void)
} }
/* Return the text name of the current function, suitably prettified /* 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 * const char *
fname_as_string (int pretty_p) fname_as_string (int pretty_p)
{ {
const char *name = "top level"; const char *name = "top level";
char *namep;
int vrb = 2; int vrb = 2;
if (! pretty_p) if (! pretty_p)
...@@ -1103,7 +1104,26 @@ fname_as_string (int pretty_p) ...@@ -1103,7 +1104,26 @@ fname_as_string (int pretty_p)
if (current_function_decl) if (current_function_decl)
name = lang_hooks.decl_printable_name (current_function_decl, vrb); 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 /* Return the VAR_DECL for a const char array naming the current
......
...@@ -2362,6 +2362,7 @@ c_make_fname_decl (tree id, int type_dep) ...@@ -2362,6 +2362,7 @@ c_make_fname_decl (tree id, int type_dep)
DECL_ARTIFICIAL (decl) = 1; DECL_ARTIFICIAL (decl) = 1;
init = build_string (length + 1, name); init = build_string (length + 1, name);
free ((char *) name);
TREE_TYPE (init) = type; TREE_TYPE (init) = type;
DECL_INITIAL (decl) = init; DECL_INITIAL (decl) = init;
......
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "\"foobar\"" } } */
const char *str;
void foobar (void)
{
str = __FUNCTION__;
}
/* { dg-do compile }
{ dg-require-iconv "IBM-1047" }
{ dg-final { scan-assembler-not "\"foobar\"" } } */
const char *str;
void foobar (void)
{
str = __FUNCTION__;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment