aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorNiall Douglas <s_fsfeurope2@nedprod.com>2004-07-25 22:52:22 +0000
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>2004-07-25 22:52:22 +0000
commitd7afec4b079f40ba7857ae1c898ed537b5c14313 (patch)
treef9985edc87f0241509ea6f38be708082bb83209a /gcc/c-common.c
parent28dab13236a7f958a8dc533363dcbe8e18eeeae5 (diff)
downloadgcc-d7afec4b079f40ba7857ae1c898ed537b5c14313.zip
gcc-d7afec4b079f40ba7857ae1c898ed537b5c14313.tar.gz
gcc-d7afec4b079f40ba7857ae1c898ed537b5c14313.tar.bz2
re PR c++/9283 (__attribute__((visibility ("hidden"))) not supported for class/struct)
PR c++/9283 PR c++/15000 * c-common.c (c_common_attribute_table): Allow handle_visibility_attribute to be called for types. (handle_visibility_attribute) When given a type, set the visibility bits on the TYPE_NAME. When given a decl, don't set no_add_attrs so that we can check later whether the attribute was present. Added warning if attribute applied to non class type. * c-decl.c (diagnose_mismatched_decls): Updated rules for merging decls and checking that they are consistent. * common.opt: Added -fvisibility. * c.opt, c-opts.c: Added -fvisibility-inlines-hidden. * c-pragma.h, c-pragma.c: Added handle_pragma_visibility(). * flags.h, tree.h: Added assorted support defines for overall patch * opts.c: Added parsing support for -fvisibility. * tree.c (build_decl): Set visibility for all decls to be whatever is in force at that time. * varasm.c (default_binds_local_p_1): Reworked logic determining when to make a symbol locally bound. * doc/invoke.texi: Added documentation for -fvisibility and -fvisibility-inlines-hidden. PR c++/15000 PR c++/9283 * class.c (check_field_decls): Apply hidden visibility if -fvisibility-inlines-hidden and inlined unless otherwise specified (build_vtable): Set vtable visibility to class visibility. (check_field_decls): Default static member visibility to class visibility. (check_methods): Default method visibility to class visibility. * cp-tree.h: Added CLASSTYPE_VISIBILITY and CLASSTYPE_VISIBILITY_SPECIFIED macro. * decl.c (duplicate_decls): New logic for merging definition decls with declaration decls. Added ignore & warning when non default applied to global operator new or delete. * method.c, optimize.c, rtti.c: Added setting of VISIBILITY_SPECIFIED wherever VISIBILITY was changed * rtti.c (get_tinfo_decl): Set typeinfo visibility to class visibility. (tinfo_base_init): Set typeinfo name visibility to class visibility. PR c++/9283 PR c++/15000 * gcc.dg/visibility-9.c, gcc.dg/visibility-a.c: New tests. * g++.dg/ext/visibility/: New directory. * g++.dg/ext/visibility-1.C, g++.dg/ext/visibility-2.C g++.dg/ext/visibility-3.C, g++.dg/ext/visibility-4.C, g++.dg/ext/visibility-5.C, g++.dg/ext/visibility-6.C, g++.dg/ext/visibility-7.C: Move to g++.dg/ext/visibility/. * g++.dg/ext/visibility/fvisibility.C, g++.dg/ext/visibility/fvisibility-inlines-hidden.C, g++.dg/ext/visibility/fvisibility-override1.C g++.dg/ext/visibility/fvisibility-override2.C g++.dg/ext/visibility/memfuncts.C g++.dg/ext/visibility/noPLT.C g++.dg/ext/visibility/pragma.C g++.dg/ext/visibility/pragma-override1.C g++.dg/ext/visibility/pragma-override2.C g++.dg/ext/visibility/staticmemfuncts.C g++.dg/ext/visibility/virtual.C: New tests. Co-Authored-By: Brian Ryner <bryner@brianryner.com> From-SVN: r85167
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index ddd8e87..2fe696d 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -616,7 +616,7 @@ const struct attribute_spec c_common_attribute_table[] =
handle_deprecated_attribute },
{ "vector_size", 1, 1, false, true, false,
handle_vector_size_attribute },
- { "visibility", 1, 1, true, false, false,
+ { "visibility", 1, 1, false, false, false,
handle_visibility_attribute },
{ "tls_model", 1, 1, true, false, false,
handle_tls_model_attribute },
@@ -4563,7 +4563,16 @@ handle_visibility_attribute (tree *node, tree name, tree args,
*no_add_attrs = true;
- if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
+ if (TYPE_P (*node))
+ {
+ if (TREE_CODE (*node) != RECORD_TYPE && TREE_CODE (*node) != UNION_TYPE)
+ {
+ warning ("`%s' attribute ignored on non-class types",
+ IDENTIFIER_POINTER (name));
+ return NULL_TREE;
+ }
+ }
+ else if (decl_function_context (decl) != 0 || ! TREE_PUBLIC (decl))
{
warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
return NULL_TREE;
@@ -4574,6 +4583,14 @@ handle_visibility_attribute (tree *node, tree name, tree args,
error ("visibility arg not a string");
return NULL_TREE;
}
+
+ /* If this is a type, set the visibility on the type decl. */
+ if (TYPE_P (decl))
+ {
+ decl = TYPE_NAME (decl);
+ if (! decl)
+ return NULL_TREE;
+ }
if (strcmp (TREE_STRING_POINTER (id), "default") == 0)
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
@@ -4585,6 +4602,14 @@ handle_visibility_attribute (tree *node, tree name, tree args,
DECL_VISIBILITY (decl) = VISIBILITY_PROTECTED;
else
error ("visibility arg must be one of \"default\", \"hidden\", \"protected\" or \"internal\"");
+ DECL_VISIBILITY_SPECIFIED (decl) = 1;
+
+ /* For decls only, go ahead and attach the attribute to the node as well.
+ This is needed so we can determine whether we have VISIBILITY_DEFAULT
+ because the visibility was not specified, or because it was explicitly
+ overridden from the class visibility. */
+ if (DECL_P (*node))
+ *no_add_attrs = false;
return NULL_TREE;
}