<div dir='auto'><div>Hi Richard,</div><div dir="auto"><br></div><div dir="auto">Thank you for the heads up. Feel free to revert, or I can when I can get back to a terminal. I'm not sure where the right place is to warn if using the linkage calculator here is too early, so it might take a bit of time for me to fix the patch.</div><div dir="auto"><br></div><div dir="auto">Thanks,</div><div dir="auto">Scott<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On May 2, 2019 9:42 PM, Richard Smith <richard@metafoo.co.uk> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">This will trigger computation and caching the linkage of the
<br>
declaration too early (before we actually know it) in some cases. For
<br>
instance, I believe this is causing a rejects-valid on:
<br>

<br>
typedef struct __attribute__((visibility("hidden"))) {} A;
<br>

<br>
... which we used to accept but now reject with:
<br>

<br>
<stdin>:1:31: warning: 'visibility' attribute is ignored on a
<br>
non-external symbol [-Wignored-attributes]
<br>
typedef struct __attribute__((visibility("hidden"))) {} A;
<br>
                              ^
<br>
<stdin>:1:57: error: unsupported: typedef changes linkage of anonymous
<br>
type, but linkage was already computed
<br>
typedef struct __attribute__((visibility("hidden"))) {} A;
<br>
                                                        ^
<br>
<stdin>:1:15: note: use a tag name here to establish linkage prior to definition
<br>
typedef struct __attribute__((visibility("hidden"))) {} A;
<br>
              ^
<br>
               A
<br>

<br>
In addition to the error, note that the warning is wrong, because the
<br>
linkage was computed too early (before it was known).
<br>

<br>
On Thu, 2 May 2019 at 12:01, Scott Linder via cfe-commits
<br>
<cfe-commits@lists.llvm.org> wrote:
<br>
>
<br>
> Author: scott.linder
<br>
> Date: Thu May  2 12:03:57 2019
<br>
> New Revision: 359814
<br>
>
<br>
> URL: http://llvm.org/viewvc/llvm-project?rev=359814&view=rev
<br>
> Log:
<br>
> [Sema] Emit warning for visibility attribute on internal-linkage declaration
<br>
>
<br>
> GCC warns on these cases, but we currently just silently ignore the attribute.
<br>
>
<br>
> Differential Revision: https://reviews.llvm.org/D61097
<br>
>
<br>
> Modified:
<br>
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
<br>
>     cfe/trunk/lib/Sema/SemaDeclAttr.cpp
<br>
>     cfe/trunk/test/Sema/attr-visibility.c
<br>
>     cfe/trunk/test/SemaCXX/ast-print.cpp
<br>
>     cfe/trunk/test/SemaCXX/attr-visibility.cpp
<br>
>
<br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
<br>
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=359814&r1=359813&r2=359814&view=diff
<br>
> ==============================================================================
<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May  2 12:03:57 2019
<br>
> @@ -2778,6 +2778,9 @@ def warn_attribute_ignored : Warning<"%0
<br>
>  def warn_attribute_ignored_on_inline :
<br>
>    Warning<"%0 attribute ignored on inline function">,
<br>
>    InGroup<IgnoredAttributes>;
<br>
> +def warn_attribute_ignored_on_non_external :
<br>
> +  Warning<"%0 attribute is ignored on a non-external symbol">,
<br>
> +  InGroup<IgnoredAttributes>;
<br>
>  def warn_nocf_check_attribute_ignored :
<br>
>    Warning<"'nocf_check' attribute ignored; use -fcf-protection to enable the attribute">,
<br>
>    InGroup<IgnoredAttributes>;
<br>
>
<br>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
<br>
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=359814&r1=359813&r2=359814&view=diff
<br>
> ==============================================================================
<br>
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
<br>
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu May  2 12:03:57 2019
<br>
> @@ -2615,6 +2615,14 @@ static void handleVisibilityAttr(Sema &S
<br>
>      return;
<br>
>    }
<br>
>
<br>
> +  // Visibility attributes have no effect on symbols with internal linkage.
<br>
> +  if (const auto *ND = dyn_cast<NamedDecl>(D)) {
<br>
> +    if (!ND->isExternallyVisible())
<br>
> +      S.Diag(AL.getRange().getBegin(),
<br>
> +             diag::warn_attribute_ignored_on_non_external)
<br>
> +          << AL;
<br>
> +  }
<br>
> +
<br>
>    // Check that the argument is a string literal.
<br>
>    StringRef TypeStr;
<br>
>    SourceLocation LiteralLoc;
<br>
>
<br>
> Modified: cfe/trunk/test/Sema/attr-visibility.c
<br>
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-visibility.c?rev=359814&r1=359813&r2=359814&view=diff
<br>
> ==============================================================================
<br>
> --- cfe/trunk/test/Sema/attr-visibility.c (original)
<br>
> +++ cfe/trunk/test/Sema/attr-visibility.c Thu May  2 12:03:57 2019
<br>
> @@ -26,3 +26,9 @@ typedef int __attribute__((visibility("d
<br>
>  int x __attribute__((type_visibility("default"))); // expected-error {{'type_visibility' attribute only applies to types and namespaces}}
<br>
>
<br>
>  int PR17105 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}
<br>
> +
<br>
> +static int test8 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
> +static int test9 __attribute__((visibility("hidden"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
> +static int test10 __attribute__((visibility("internal"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
> +
<br>
> +static int test11() __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
>
<br>
> Modified: cfe/trunk/test/SemaCXX/ast-print.cpp
<br>
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print.cpp?rev=359814&r1=359813&r2=359814&view=diff
<br>
> ==============================================================================
<br>
> --- cfe/trunk/test/SemaCXX/ast-print.cpp (original)
<br>
> +++ cfe/trunk/test/SemaCXX/ast-print.cpp Thu May  2 12:03:57 2019
<br>
> @@ -209,10 +209,8 @@ void test(int i) {
<br>
>  }
<br>
>  }
<br>
>
<br>
> -namespace {
<br>
>  // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
<br>
>  struct [[gnu::visibility("hidden")]] S;
<br>
> -}
<br>
>
<br>
>  // CHECK:      struct CXXFunctionalCastExprPrint {
<br>
>  // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
<br>
>
<br>
> Modified: cfe/trunk/test/SemaCXX/attr-visibility.cpp
<br>
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-visibility.cpp?rev=359814&r1=359813&r2=359814&view=diff
<br>
> ==============================================================================
<br>
> --- cfe/trunk/test/SemaCXX/attr-visibility.cpp (original)
<br>
> +++ cfe/trunk/test/SemaCXX/attr-visibility.cpp Thu May  2 12:03:57 2019
<br>
> @@ -18,3 +18,9 @@ void foo<int>() {
<br>
>  struct x3 {
<br>
>    static int y;
<br>
>  } __attribute((visibility("default"))); // expected-warning {{attribute 'visibility' after definition is ignored}}
<br>
> +
<br>
> +const int test4 __attribute__((visibility("default"))) = 0; // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
> +
<br>
> +namespace {
<br>
> +  int test5 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
<br>
> +};
<br>
>
<br>
>
<br>
> _______________________________________________
<br>
> cfe-commits mailing list
<br>
> cfe-commits@lists.llvm.org
<br>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
<br>
</p>
</blockquote></div><br></div></div></div>