aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2004-05-28 21:56:59 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2004-05-28 21:56:59 +0000
commit0d0bc03606fc5c4d655130b9f060b018412187cf (patch)
tree03c713e614f2501fa7abc0b4ad076f2a234f562e
parent4bb4ae964aaf3ef1dd86d2b595a022a9961aee5b (diff)
downloadgcc-0d0bc03606fc5c4d655130b9f060b018412187cf.zip
gcc-0d0bc03606fc5c4d655130b9f060b018412187cf.tar.gz
gcc-0d0bc03606fc5c4d655130b9f060b018412187cf.tar.bz2
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
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/c-common.c24
-rw-r--r--gcc/c-decl.c1
-rw-r--r--gcc/testsuite/g++.dg/charset/function.cc10
-rw-r--r--gcc/testsuite/gcc.dg/charset/function.c10
5 files changed, 57 insertions, 2 deletions
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 <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.
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__;
+}