c++: visibility of local extern [PR103291]
authorJason Merrill <jason@redhat.com>
Sun, 27 Mar 2022 13:44:59 +0000 (09:44 -0400)
committerJason Merrill <jason@redhat.com>
Mon, 28 Mar 2022 13:35:58 +0000 (09:35 -0400)
When setting up the hidden namespace-scope decl for a local extern, we also
need to set its visibility.

PR c++/103291

gcc/cp/ChangeLog:

* name-lookup.cc (push_local_extern_decl_alias): Call
determine_visibility.

gcc/testsuite/ChangeLog:

* g++.dg/ext/visibility/visibility-local-extern1.C: New test.

gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/ext/visibility/visibility-local-extern1.C [new file with mode: 0644]

index 3c7b626..c833b84 100644 (file)
@@ -3476,6 +3476,9 @@ push_local_extern_decl_alias (tree decl)
              && CP_DECL_THREAD_LOCAL_P (decl)
              && alias != error_mark_node)
            set_decl_tls_model (alias, DECL_TLS_MODEL (decl));
+
+         /* Adjust visibility.  */
+         determine_visibility (alias);
        }
     }
 
diff --git a/gcc/testsuite/g++.dg/ext/visibility/visibility-local-extern1.C b/gcc/testsuite/g++.dg/ext/visibility/visibility-local-extern1.C
new file mode 100644 (file)
index 0000000..40c2019
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/103291
+// { dg-additional-options -fpic }
+// { dg-final { scan-assembler-not "@GOTPCREL" } }
+
+#pragma GCC visibility push(hidden)
+
+int hidden_fetch(void) {
+  extern const int hidden_global;
+  return hidden_global;
+}