From patchwork Fri Oct 21 08:00:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Agostino Vitillo X-Patchwork-Id: 120955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id DEF97B6F89 for ; Fri, 21 Oct 2011 19:00:58 +1100 (EST) Received: (qmail 18202 invoked by alias); 21 Oct 2011 08:00:53 -0000 Received: (qmail 18190 invoked by uid 22791); 21 Oct 2011 08:00:51 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ironport3.lbl.gov (HELO ironport3.lbl.gov) (128.3.41.25) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 08:00:37 +0000 X-Ironport-SBRS: 4.4 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcBACImoU5KfVK0kGdsb2JhbABDqRQIIgEBAQEJCQ0HFAQhggcCJj+BFQEFATUin1YKnHKHSGEEoSs9g3E Received: from mail-wy0-f180.google.com ([74.125.82.180]) by ironport3.lbl.gov with ESMTP; 21 Oct 2011 01:00:34 -0700 Received: by wyg24 with SMTP id 24so5989703wyg.39 for ; Fri, 21 Oct 2011 01:00:33 -0700 (PDT) Received: by 10.216.159.201 with SMTP id s51mr9934489wek.70.1319184033553; Fri, 21 Oct 2011 01:00:33 -0700 (PDT) Received: from pb-d-128-141-224-204.cern.ch (pb-d-128-141-224-204.cern.ch. [128.141.224.204]) by mx.google.com with ESMTPS id x40sm13955338wbn.19.2011.10.21.01.00.31 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Oct 2011 01:00:32 -0700 (PDT) From: Roberto Agostino Vitillo Subject: [C++ Patch] PR 30066 Date: Fri, 21 Oct 2011 10:00:31 +0200 Message-Id: <1F1A5107-8C1D-411E-9048-EECA2EE3764E@lbl.gov> Cc: jason@redhat.com, Paolo Carlini , Vincenzo Innocente To: gcc-patches@gcc.gnu.org Mime-Version: 1.0 (Apple Message framework v1251.1) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org With this patch fvisibility-inlines-hidden affects also inline functions, e.g.: inline void foo() {} int main(){ foo(); return 0; } when compiled with -fvisibility-inlines-hidden, foo has hidden visibility: ... 10: 0000000000000000 6 FUNC WEAK HIDDEN 6 _Z3foov ... Tested on x86_64-linux. I should have a signed copyright assignment in a few weeks but I think this patch is small enough that it doesn't need it. r 2011-10-21 Roberto Agostino Vitillo PR c++/30066 * gcc/doc/invoke.texi: Documentation change for fvisibility-inlines-hidden. * gcc/c-family/c.opt: Description change for fvisibility-inlines-hidden. * gcc/cp/decl2.c (determine_hidden_inline): New function. (determine_visibility): fvisibility-inlines-hidden affects inline functions. * gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-4.C: New test. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 180234) +++ gcc/doc/invoke.texi (working copy) @@ -2120,7 +2120,7 @@ @item -fvisibility-inlines-hidden @opindex fvisibility-inlines-hidden This switch declares that the user does not attempt to compare -pointers to inline methods where the addresses of the two functions +pointers to inline functions or methods where the addresses of the two functions were taken in different shared objects. The effect of this is that GCC may, effectively, mark inline methods with Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (revision 180234) +++ gcc/c-family/c.opt (working copy) @@ -1043,7 +1043,7 @@ fvisibility-inlines-hidden C++ ObjC++ -Marks all inlined methods as having hidden visibility +Marks all inlined functions and methods as having hidden visibility fvisibility-ms-compat C++ ObjC++ Var(flag_visibility_ms_compat) Index: gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-4.C =================================================================== --- gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-4.C (revision 0) +++ gcc/testsuite/g++.dg/ext/visibility/fvisibility-inlines-hidden-4.C (revision 0) @@ -0,0 +1,18 @@ +/* PR c++/30066: Test that -fvisibility-inlines-hidden affects functions. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-options "-fvisibility-inlines-hidden" } */ +/* { dg-final { scan-hidden "_Z3barv" } } */ +/* { dg-final { scan-hidden "_Z3fooIvEvv" } } */ + +inline void bar() { } + +template +inline void foo() { } + +int main(void) +{ + bar(); + foo(); + return 0; +} Index: gcc/cp/decl2.c =================================================================== --- gcc/cp/decl2.c (revision 180234) +++ gcc/cp/decl2.c (working copy) @@ -86,6 +86,7 @@ static void import_export_class (tree); static tree get_guard_bits (tree); static void determine_visibility_from_class (tree, tree); +static bool determine_hidden_inline (tree); static bool decl_defined_p (tree); /* A list of static class variables. This is needed, because a @@ -2131,13 +2132,16 @@ } else if (use_template) /* Template instantiations and specializations get visibility based - on their template unless they override it with an attribute. */; + on their template unless they override it with an attribute. */; else if (! DECL_VISIBILITY_SPECIFIED (decl)) { - /* Set default visibility to whatever the user supplied with - #pragma GCC visibility or a namespace visibility attribute. */ - DECL_VISIBILITY (decl) = default_visibility; - DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma; + if (!determine_hidden_inline (decl)) + { + /* Set default visibility to whatever the user supplied with + #pragma GCC visibility or a namespace visibility attribute. */ + DECL_VISIBILITY (decl) = default_visibility; + DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma; + } } } @@ -2155,7 +2159,9 @@ int depth = TMPL_ARGS_DEPTH (args); tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo)); - if (!DECL_VISIBILITY_SPECIFIED (decl)) + if (!DECL_VISIBILITY_SPECIFIED (decl) + && (DECL_VISIBILITY_SPECIFIED (pattern) + || !determine_hidden_inline (decl))) { DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern); DECL_VISIBILITY_SPECIFIED (decl) @@ -2214,17 +2220,7 @@ if (DECL_VISIBILITY_SPECIFIED (decl)) return; - if (visibility_options.inlines_hidden - /* Don't do this for inline templates; specializations might not be - inline, and we don't want them to inherit the hidden - visibility. We'll set it here for all inline instantiations. */ - && !processing_template_decl - && TREE_CODE (decl) == FUNCTION_DECL - && DECL_DECLARED_INLINE_P (decl) - && (! DECL_LANG_SPECIFIC (decl) - || ! DECL_EXPLICIT_INSTANTIATION (decl))) - DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; - else + if (!determine_hidden_inline (decl)) { /* Default to the class visibility. */ DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type); @@ -2247,6 +2243,26 @@ targetm.cxx.determine_class_data_visibility (decl); } +static bool +determine_hidden_inline (tree decl) +{ + if (visibility_options.inlines_hidden + /* Don't do this for inline templates; specializations might not be + * inline, and we don't want them to inherit the hidden + * visibility. We'll set it here for all inline instantiations. */ + && !processing_template_decl + && TREE_CODE (decl) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (decl) + && (! DECL_LANG_SPECIFIC (decl) + || ! DECL_EXPLICIT_INSTANTIATION (decl))) + { + DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; + return true; + } + + return false; +} + /* Constrain the visibility of a class TYPE based on the visibility of its field types. Warn if any fields require lesser visibility. */