OSDN Git Service

Index: gcc/ChangeLog
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 Jun 2007 19:31:45 +0000 (19:31 +0000)
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 28 Jun 2007 19:31:45 +0000 (19:31 +0000)
2007-06-21  Geoffrey Keating  <geoffk@apple.com>

* doc/invoke.texi (C++ Dialect Options): Document
fvisibility-ms-compat.
* c.opt (fvisibility-ms-compat): New.

Index: gcc/cp/ChangeLog
2007-06-21  Geoffrey Keating  <geoffk@apple.com>

* decl2.c (determine_visibility): Implement
flag_visibility_ms_compat effect on type info.
* decl.c (cxx_init_decl_processing): Implement
global effect of flag_visibility_ms_compat.

Index: gcc/testsuite/ChangeLog
2007-06-26  Geoffrey Keating  <geoffk@apple.com>

* g++.dg/ext/visibility/ms-compat-1.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126088 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c.opt
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/visibility/ms-compat-1.C [new file with mode: 0644]

index f1ff630..638d8fb 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-28  Geoffrey Keating  <geoffk@apple.com>
+
+       * doc/invoke.texi (C++ Dialect Options): Document
+       fvisibility-ms-compat.
+       * c.opt (fvisibility-ms-compat): New.
+
 2007-06-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR tree-opt/32417
index 63e2bda..fc19174 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -767,6 +767,10 @@ fvisibility-inlines-hidden
 C++ ObjC++
 Marks all inlined methods as having hidden visibility
 
+fvisibility-ms-compat
+C++ ObjC++ Var(flag_visibility_ms_compat)
+Changes visibility to match Microsoft Visual Studio by default
+
 fvtable-gc
 C++ ObjC++
 Discard unused virtual functions
index 55accab..b4dce8d 100644 (file)
@@ -1,5 +1,12 @@
 2007-06-28  Geoffrey Keating  <geoffk@apple.com>
 
+       * decl2.c (determine_visibility): Implement
+       flag_visibility_ms_compat effect on type info.
+       * decl.c (cxx_init_decl_processing): Implement
+       global effect of flag_visibility_ms_compat.
+
+2007-06-28  Geoffrey Keating  <geoffk@apple.com>
+
        * decl2.c (start_objects): Mark constructor-runnning function
        as artificial.
 
index 7d4123f..8f9db1e 100644 (file)
@@ -3179,6 +3179,9 @@ cxx_init_decl_processing (void)
 
   current_lang_name = NULL_TREE;
 
+  if (flag_visibility_ms_compat)
+    default_visibility = VISIBILITY_HIDDEN;
+
   /* Force minimum function alignment if using the least significant
      bit of function pointers to store the virtual bit.  */
   if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_pfn
index 9ad06b4..a44c46d 100644 (file)
@@ -1716,6 +1716,19 @@ determine_visibility (tree decl)
             but have no TEMPLATE_INFO, so don't try to check it.  */
          use_template = 0;
        }
+      else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl)
+              && flag_visibility_ms_compat)
+       {
+         /* Under -fvisibility-ms-compat, types are visible by default,
+            even though their contents aren't.  */
+         tree underlying_type = TREE_TYPE (DECL_NAME (decl));
+         int underlying_vis = type_visibility (underlying_type);
+         if (underlying_vis == VISIBILITY_ANON
+             || CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type))
+           constrain_visibility (decl, underlying_vis);
+         else
+           DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
+       }
       else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
        {
          /* tinfo visibility is based on the type it's for.  */
index d12a627..47752e7 100644 (file)
@@ -191,6 +191,7 @@ in the following sections.
 -frepo  -fno-rtti  -fstats  -ftemplate-depth-@var{n} @gol
 -fno-threadsafe-statics -fuse-cxa-atexit  -fno-weak  -nostdinc++ @gol
 -fno-default-inline  -fvisibility-inlines-hidden @gol
+-fvisibility-ms-compat @gol
 -Wabi  -Wctor-dtor-privacy @gol
 -Wnon-virtual-dtor  -Wreorder @gol
 -Weffc++  -Wno-deprecated  -Wstrict-null-sentinel @gol
@@ -1830,6 +1831,40 @@ Explicitly instantiated inline methods are unaffected by this option
 as their linkage might otherwise cross a shared library boundary.
 @xref{Template Instantiation}.
 
+@item -fvisibility-ms-compat
+@opindex fvisibility-ms-compat
+This flag attempts to use visibility settings to make GCC's C++
+linkage model compatible with that of Microsoft Visual Studio.
+
+The flag makes these changes to GCC's linkage model:
+
+@enumerate
+@item
+It sets the default visibility to @code{hidden}, like
+@option{-fvisibility=hidden}.
+
+@item
+Types, but not their members, are not hidden by default.
+
+@item
+The One Definition Rule is relaxed for types without explicit
+visibility specifications which are defined in more than one different
+shared object: those declarations are permitted if they would have
+been permitted when this option was not used.
+@end enumerate
+
+In new code it is better to use @option{-fvisibility=hidden} and
+export those classes which are intended to be externally visible.
+Unfortunately it is possible for code to rely, perhaps accidentally,
+on the Visual Studio behaviour.
+
+Among the consequences of these changes are that static data members
+of the same type with the same name but defined in different shared
+objects will be different, so changing one will not change the other;
+and that pointers to function members defined in different shared
+objects may not compare equal.  When this flag is given, it is a
+violation of the ODR to define types with the same name differently.
+
 @item -fno-weak
 @opindex fno-weak
 Do not use weak symbol support, even if it is provided by the linker.
index 9d5b05d..93bc110 100644 (file)
@@ -1,3 +1,7 @@
+2007-06-28  Geoffrey Keating  <geoffk@apple.com>
+
+       * g++.dg/ext/visibility/ms-compat-1.C: New.
+
 2007-06-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR tree-opt/32417
diff --git a/gcc/testsuite/g++.dg/ext/visibility/ms-compat-1.C b/gcc/testsuite/g++.dg/ext/visibility/ms-compat-1.C
new file mode 100644 (file)
index 0000000..e0fd01e
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-require-visibility "" } */
+/* { dg-options "-fvisibility-ms-compat" } */
+
+/* { dg-final { scan-not-hidden "__ZTI1S" } } */
+/* { dg-final { scan-hidden "__ZTI1T" } } */
+/* { dg-final { scan-not-hidden "__ZTI1U" } } */
+/* { dg-final { scan-not-hidden "__ZN1U6hide_4Ev" } } */
+
+class S {
+  virtual void hide_2();
+} hide_1;
+
+void S::hide_2() {
+}
+
+class __attribute__((visibility("hidden"))) T {
+  virtual void hide_4();
+} hide_3;
+
+void T::hide_4() {
+}
+
+class __attribute__((visibility("default"))) U {
+  virtual void hide_4();
+};
+
+void U::hide_4() {
+}