From a2aa65f063a85d23f961337510d3a9395d79de41 Mon Sep 17 00:00:00 2001 From: Geoffrey Keating Date: Sun, 6 May 2007 00:01:36 +0000 Subject: [PATCH] Index: libiberty/ChangeLog 2007-05-04 Geoffrey Keating * cp-demangle.c (d_name): Detect local-source-name. (d_prefix): Likewise. (d_unqualified_name): Implement local-source-name. Index: gcc/cp/ChangeLog 2007-05-04 Geoffrey Keating PR 31775 * mangle.c (write_mangled_name): Mangle static variable names. (write_unqualified_name): Use local-source-name for namespace-scope static variables. Index: gcc/testsuite/ChangeLog 2007-05-04 Geoffrey Keating PR 31775 * g++.dg/other/nested-extern.cc: New. * g++.dg/other/nested-extern-1.C: New. * g++.dg/other/nested-extern-2.C: New. From-SVN: r124467 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/mangle.c | 18 ++++++++++++++-- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/other/nested-extern-1.C | 17 +++++++++++++++ gcc/testsuite/g++.dg/other/nested-extern-2.C | 18 ++++++++++++++++ gcc/testsuite/g++.dg/other/nested-extern.cc | 1 + libiberty/ChangeLog | 6 ++++++ libiberty/cp-demangle.c | 22 +++++++++++++++++++- libiberty/testsuite/demangle-expected | 16 ++++++++++++++ 9 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/nested-extern-1.C create mode 100644 gcc/testsuite/g++.dg/other/nested-extern-2.C create mode 100644 gcc/testsuite/g++.dg/other/nested-extern.cc diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 52bf5e8654c8..b4a1c9a1b0a3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-05-05 Geoffrey Keating + + PR 31775 + * mangle.c (write_mangled_name): Mangle static variable names. + (write_unqualified_name): Use local-source-name for + namespace-scope static variables. + 2007-05-04 Dirk Mueller * cp-tree.h (DECL_MAIN_P): only if -ffreestanding is diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 40c059ad63ce..31676e7b4540 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -688,7 +688,8 @@ write_mangled_name (const tree decl, bool top_level) } } else if (TREE_CODE (decl) == VAR_DECL - /* The names of global variables aren't mangled. */ + /* The names of non-static global variables aren't mangled. */ + && DECL_EXTERNAL_LINKAGE_P (decl) && (CP_DECL_CONTEXT (decl) == global_namespace /* And neither are `extern "C"' variables. */ || DECL_EXTERN_C_P (decl))) @@ -1086,7 +1087,10 @@ write_template_prefix (const tree node) ::= ::= - ::= */ + ::= + ::= + + ::= L */ static void write_unqualified_name (const tree decl) @@ -1126,6 +1130,16 @@ write_unqualified_name (const tree decl) write_string (oni[DECL_OVERLOADED_OPERATOR_P (decl)].mangled_name); } + else if (VAR_OR_FUNCTION_DECL_P (decl) && ! TREE_PUBLIC (decl) + && DECL_NAMESPACE_SCOPE_P (decl) + && decl_linkage (decl) == lk_internal) + { + MANGLE_TRACE_TREE ("local-source-name", decl); + write_char ('L'); + write_source_name (DECL_NAME (decl)); + /* The default discriminator is 1, and that's all we ever use, + so there's no code to output one here. */ + } else write_source_name (DECL_NAME (decl)); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c8ea1b29ae3c..586cc74f5297 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2007-05-05 Geoffrey Keating + + PR 31775 + * g++.dg/other/nested-extern.cc: New. + * g++.dg/other/nested-extern-1.C: New. + * g++.dg/other/nested-extern-2.C: New. + 2007-05-04 Daniel Franke PR fortran/31760 diff --git a/gcc/testsuite/g++.dg/other/nested-extern-1.C b/gcc/testsuite/g++.dg/other/nested-extern-1.C new file mode 100644 index 000000000000..6533a2ade51a --- /dev/null +++ b/gcc/testsuite/g++.dg/other/nested-extern-1.C @@ -0,0 +1,17 @@ +/* { dg-do run } */ +// { dg-additional-sources "nested-extern.cc" } +/* PR 31775 */ +extern "C" void abort(); +extern int *p; +int main() +{ + extern int i; + i = 1; + *p = 2; + if (i == 2) + abort (); + return 0; +} + +static int i; +int *p = &i; diff --git a/gcc/testsuite/g++.dg/other/nested-extern-2.C b/gcc/testsuite/g++.dg/other/nested-extern-2.C new file mode 100644 index 000000000000..58f53e083f9d --- /dev/null +++ b/gcc/testsuite/g++.dg/other/nested-extern-2.C @@ -0,0 +1,18 @@ +/* { dg-do run } */ +// { dg-additional-sources "nested-extern.cc" } +/* PR 31775 */ +extern "C" void abort(); +static int i; +int *p = &i; +int main() +{ + int i; + { + extern int i; + i = 1; + *p = 2; + if (i == 2) + abort (); + } + return 0; +} diff --git a/gcc/testsuite/g++.dg/other/nested-extern.cc b/gcc/testsuite/g++.dg/other/nested-extern.cc new file mode 100644 index 000000000000..048f715b4656 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/nested-extern.cc @@ -0,0 +1 @@ +int i; diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 431ef1db2ff6..c4e707210369 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2007-05-05 Geoffrey Keating + + * cp-demangle.c (d_name): Detect local-source-name. + (d_prefix): Likewise. + (d_unqualified_name): Implement local-source-name. + 2007-05-03 Joel Brobecker * filename_cmp.c: Replace include of ctype.h by include of diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 5c930c6ab3f2..992b3580bf7c 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -1100,6 +1100,9 @@ d_name (struct d_info *di) case 'Z': return d_local_name (di); + case 'L': + return d_unqualified_name (di); + case 'S': { int subst; @@ -1220,7 +1223,8 @@ d_prefix (struct d_info *di) if (IS_DIGIT (peek) || IS_LOWER (peek) || peek == 'C' - || peek == 'D') + || peek == 'D' + || peek == 'L') dc = d_unqualified_name (di); else if (peek == 'S') dc = d_substitution (di, 1); @@ -1254,6 +1258,9 @@ d_prefix (struct d_info *di) /* ::= ::= ::= + ::= + + ::= L */ static struct demangle_component * @@ -1275,6 +1282,19 @@ d_unqualified_name (struct d_info *di) } else if (peek == 'C' || peek == 'D') return d_ctor_dtor_name (di); + else if (peek == 'L') + { + struct demangle_component * ret; + + d_advance (di, 1); + + ret = d_source_name (di); + if (ret == NULL) + return NULL; + if (! d_discriminator (di)) + return NULL; + return ret; + } else return NULL; } diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 471819e26c0f..f1afc45c8c9b 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3842,3 +3842,19 @@ _ZNT --format=gnu-v3 _Z1aMark _Z1aMark +# test 1 +--format=gnu-v3 +_ZL3foo_2 +foo +# test 2 +--format=gnu-v3 +_ZZL3foo_2vE4var1 +foo()::var1 +# test 3 +--format=gnu-v3 +_ZZL3foo_2vE4var1_0 +foo()::var1 +# test 4 +--format=gnu-v3 +_ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct +myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct)