From 7c0de6a544ba5d293eab1f91b70e017ef5d5834f Mon Sep 17 00:00:00 2001 From: Geoffrey Keating Date: Thu, 13 Jul 2006 06:16:59 +0000 Subject: [PATCH] Index: ChangeLog 2006-07-12 Geoffrey Keating * doc/invoke.texi (C++ Dialect Options): Explain difference between -fvisibility-inlines-hidden and setting hidden visibility explicitly. Index: cp/ChangeLog 2006-07-12 Geoffrey Keating * decl2.c (determine_visibility): Don't change visibility of function locals because of -fvisibility-inlines-hidden. Index: testsuite/ChangeLog 2006-07-12 Geoffrey Keating * g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C: New. From-SVN: r115411 --- gcc/ChangeLog | 6 ++++++ gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl2.c | 15 +++++++++++---- gcc/doc/invoke.texi | 9 +++++++-- gcc/testsuite/ChangeLog | 4 ++++ .../visibility/fvisibility-inlines-hidden-2.C | 19 +++++++++++++++++++ 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4c269fca6a1..9e907dd3647 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-07-12 Geoffrey Keating + + * doc/invoke.texi (C++ Dialect Options): Explain difference + between -fvisibility-inlines-hidden and setting hidden + visibility explicitly. + 2006-07-12 Eric Christopher * config/t-slibgcc-darwin (SHLIB_LINK): Don't munge stmp-lipo. diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c7aa9186c93..de1f4f117a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2006-07-12 Geoffrey Keating + + * decl2.c (determine_visibility): Don't change visibility of + function locals because of -fvisibility-inlines-hidden. + 2006-07-12 Jason Merrill PR c++/28217 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index defeafbf551..3a78c40c223 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1712,13 +1712,20 @@ determine_visibility (tree decl) gcc_assert (TREE_CODE (decl) != VAR_DECL || !DECL_VTABLE_OR_VTT_P (decl)); - if (DECL_FUNCTION_SCOPE_P (decl)) + if (DECL_FUNCTION_SCOPE_P (decl) && ! DECL_VISIBILITY_SPECIFIED (decl)) { /* Local statics and classes get the visibility of their - containing function. */ + containing function by default, except that + -fvisibility-inlines-hidden doesn't affect them. */ tree fn = DECL_CONTEXT (decl); - DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn); - DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn); + if (DECL_VISIBILITY_SPECIFIED (fn) || ! DECL_CLASS_SCOPE_P (fn)) + { + DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn); + DECL_VISIBILITY_SPECIFIED (decl) = + DECL_VISIBILITY_SPECIFIED (fn); + } + else + determine_visibility_from_class (decl, DECL_CONTEXT (fn)); /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set, but have no TEMPLATE_INFO, so don't try to check it. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 59830ecde15..0a1a917d914 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1618,10 +1618,15 @@ when used within the DSO@. Enabling this option can have a dramatic effect on load and link times of a DSO as it massively reduces the size of the dynamic export table when the library makes heavy use of templates. +The behaviour of this switch is not quite the same as marking the +methods as hidden directly, because it does not affect static variables +local to the function or cause the compiler to deduce that +the function is defined in only one shared object. + You may mark a method as having a visibility explicitly to negate the effect of the switch for that method. For example, if you do want to -compare pointers to a particular inline method, or the method has -local static data, you might mark it as having default visibility. +compare pointers to a particular inline method, you might mark it as +having default visibility. @item -fno-weak @opindex fno-weak diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e1961661935..15484111c2d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-07-12 Geoffrey Keating + + * g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C: New. + 2006-07-13 Paul Thomas PR fortran/25097 diff --git a/gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C b/gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C new file mode 100644 index 00000000000..ed38ebefe9d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-2.C @@ -0,0 +1,19 @@ +/* Test that -fvisibility-inlines-hidden doesn't affect static variables. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-options "-fvisibility-inlines-hidden" } */ +/* { dg-final { scan-not-hidden "_ZZN3foo7my_funcEvE1x" } } */ + +struct foo +{ + int my_func() { + static int x; + return x++; + } +}; + +int t() +{ + foo f; + return f.my_func(); +}