]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/88568
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 9 Mar 2019 12:08:23 +0000 (12:08 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 9 Mar 2019 12:08:23 +0000 (12:08 +0000)
* attribs.c (handle_dll_attribute): Don't clear TREE_STATIC for
dllimport on VAR_DECLs with RECORD_TYPE or UNION_TYPE DECL_CONTEXT.

* g++.dg/other/pr88568.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269525 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/attribs.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/pr88568.C [new file with mode: 0644]

index a4cfe91d0957498220e330e6b98e1e6f5d99eaca..5b1fb49bea11cdb37e61b0c6fd33460e9de5cfad 100644 (file)
@@ -1,5 +1,9 @@
 2019-03-09  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/88568
+       * attribs.c (handle_dll_attribute): Don't clear TREE_STATIC for
+       dllimport on VAR_DECLs with RECORD_TYPE or UNION_TYPE DECL_CONTEXT.
+
        PR target/79645
        * common.opt (fdiagnostics-show-labels,
        fdiagnostics-show-line-numbers, fdiagnostics-format=,
index a55638d9389f46ef21580b906f6488069f9226c4..adf497322daef3fe2e7d42b04f0857ed792f9aef 100644 (file)
@@ -1691,8 +1691,11 @@ handle_dll_attribute (tree * pnode, tree name, tree args, int flags,
             a function global scope, unless declared static.  */
          if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
            TREE_PUBLIC (node) = 1;
-         /* Clear TREE_STATIC because DECL_EXTERNAL is set.  */
-         TREE_STATIC (node) = 0;
+         /* Clear TREE_STATIC because DECL_EXTERNAL is set, unless
+            it is a C++ static data member.  */
+         if (DECL_CONTEXT (node) == NULL_TREE
+             || !RECORD_OR_UNION_TYPE_P (DECL_CONTEXT (node)))
+           TREE_STATIC (node) = 0;
        }
 
       if (*no_add_attrs == false)
index f32b5afeed95236bffb6b8c3db34bac86b9b8ed0..6b131cbc5fcd99b84d6692bae1ab401227d95b75 100644 (file)
@@ -1,5 +1,8 @@
 2019-03-09  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/88568
+       * g++.dg/other/pr88568.C: New test.
+
        PR rtl-optimization/89634
        * gcc.c-torture/execute/pr89634.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/other/pr88568.C b/gcc/testsuite/g++.dg/other/pr88568.C
new file mode 100644 (file)
index 0000000..9d344fd
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c/88568
+// { dg-do compile }
+// { dg-require-dll "" }
+
+struct S {
+  __attribute__((dllimport)) static const char foo[];
+};
+
+int
+foo (int x)
+{
+  return S::foo[x];
+}