charset __FUNCTION__ patch
Aldy Hernandez
aldyh@redhat.com
Fri May 28 23:43:00 GMT 2004
Testing finished. There were a few tid-bits (warnings) I got wrong--
no change to functionality. Fixed in this patch. No regressions.
--
Will hack for surf.
* 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.
Index: testsuite/g++.dg/charset/function.cc
===================================================================
RCS file: testsuite/g++.dg/charset/function.cc
diff -N testsuite/g++.dg/charset/function.cc
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/charset/function.cc 28 May 2004 18:36:00 -0000
***************
*** 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__;
+ }
Index: testsuite/gcc.dg/charset/function.c
===================================================================
RCS file: testsuite/gcc.dg/charset/function.c
diff -N testsuite/gcc.dg/charset/function.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/charset/function.c 28 May 2004 18:36:00 -0000
***************
*** 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__;
+ }
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.501
diff -c -p -r1.501 c-decl.c
*** c-decl.c 19 May 2004 01:28:49 -0000 1.501
--- c-decl.c 28 May 2004 18:36:04 -0000
*************** c_make_fname_decl (tree id, int type_dep
*** 2362,2367 ****
--- 2362,2368 ----
DECL_ARTIFICIAL (decl) = 1;
init = build_string (length + 1, name);
+ free ((char *) name);
TREE_TYPE (init) = type;
DECL_INITIAL (decl) = init;
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.501
diff -c -p -r1.501 c-common.c
*** c-common.c 22 May 2004 18:16:38 -0000 1.501
--- c-common.c 28 May 2004 18:36:06 -0000
*************** finish_fname_decls (void)
*** 1086,1097 ****
}
/* Return the text name of the current function, suitably prettified
! by PRETTY_P. */
const char *
fname_as_string (int pretty_p)
{
const char *name = "top level";
int vrb = 2;
if (! pretty_p)
--- 1086,1098 ----
}
/* Return the text name of the current function, suitably prettified
! 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)
*************** fname_as_string (int pretty_p)
*** 1103,1109 ****
if (current_function_decl)
name = lang_hooks.decl_printable_name (current_function_decl, vrb);
! return name;
}
/* Return the VAR_DECL for a const char array naming the current
--- 1104,1129 ----
if (current_function_decl)
name = lang_hooks.decl_printable_name (current_function_decl, vrb);
! if (c_lex_string_translate)
! {
! int len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
! cpp_string cstr = { 0, 0 }, strname;
!
! namep = (char *) xcalloc (len, sizeof (char));
! 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));
! strcpy (namep, name);
! }
!
! return namep;
}
/* Return the VAR_DECL for a const char array naming the current
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1210
diff -c -p -r1.1210 decl.c
*** cp/decl.c 23 May 2004 21:06:56 -0000 1.1210
--- cp/decl.c 28 May 2004 18:36:12 -0000
*************** cp_make_fname_decl (tree id, int type_de
*** 3087,3092 ****
--- 3087,3095 ----
tree init = cp_fname_init (name, &type);
tree decl = build_decl (VAR_DECL, id, type);
+ if (name)
+ free ((char *) name);
+
/* As we're using pushdecl_with_scope, we must set the context. */
DECL_CONTEXT (decl) = current_function_decl;
DECL_PRETTY_FUNCTION_P (decl) = type_dep;
More information about the Gcc-patches
mailing list