function.cc: New.
authorAldy Hernandez <aldyh@redhat.com>
Fri, 28 May 2004 21:56:59 +0000 (21:56 +0000)
committerAldy Hernandez <aldyh@gcc.gnu.org>
Fri, 28 May 2004 21:56:59 +0000 (21:56 +0000)
* 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
gcc/c-common.c
gcc/c-decl.c
gcc/testsuite/g++.dg/charset/function.cc [new file with mode: 0644]
gcc/testsuite/gcc.dg/charset/function.c [new file with mode: 0644]

index 1fa48e1d06e6246f8ccda45de37878122426e25a..a5ed97f3dc387e20305ff9c401627565e425328d 100644 (file)
@@ -1,3 +1,17 @@
+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>
 
        * stringpool.c: Add comments to PCH saving/restoring routines.
index 4aa17e622dc226cb964db2fa3f04bc8a7b784c82..3cf1baa7a8eb6417469819fa6a85df2a155ca595 100644 (file)
@@ -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
index e2c5a97a7f7094bec72c75fcc8dbb8afca8dd06d..ce39f6f54f4520674b7622561b3a9ca03c6ed6f7 100644 (file)
@@ -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 (file)
index 0000000..ab4c2bc
--- /dev/null
@@ -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 (file)
index 0000000..ab4c2bc
--- /dev/null
@@ -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__;
+}