[cfe-commits] [patch][pr12001] Avoid increasing visibility in some cases

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Sun Feb 19 18:30:56 PST 2012

With -fvisibility=hidden we currently produce a default visibility
symbol for f in

template <typename T>
struct X {
  static void f() {}
class __attribute__((visibility("default"))) A;
void g() {
  X<A> y;

GCC is able to produce a hidden symbol.

What is happening is

1 We start with an implicit default visibility
2 We merge the visibility of A, getting an explicit default visibility
3 We merge the implicit hidden visibility from the command line, but
that does nothing since we already have an explicit visibility.

We cannot simply change the merge function to give preference to more
restrictive visibilities as that would for example make everything in A

To fix this I added a specialized merge function that never increases
the visibility. It should be used in cases like the merging of the
template arguments in the above case. The are probably more cases not
yet covered by this patch where it should be used.

Just using this new function in step 2 above would not be sufficient, as
at that point we still have an default visibility. To fix this I simply
moved the handling of -fvisibility=hidden to the top. This now works as
we always keep track of the explicitness of the visibility and override
it as need.

Suggestions for a better name for mergeWithMin are welcome :-)

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr12001.patch
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120219/327b599d/attachment.ksh>

More information about the cfe-commits mailing list