From 3568d2d5fa77f5c8798c1dca46b1f738d2097202 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 9 Mar 2019 13:08:23 +0100 Subject: [PATCH] re PR c/88568 ('dllimport' no longer implies 'extern' in C) 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. * g++.dg/other/pr88568.C: New test. From-SVN: r269525 --- gcc/ChangeLog | 4 ++++ gcc/attribs.c | 7 +++++-- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/other/pr88568.C | 13 +++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/pr88568.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4cfe91d095..5b1fb49bea1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2019-03-09 Jakub Jelinek + 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=, diff --git a/gcc/attribs.c b/gcc/attribs.c index a55638d9389..adf497322da 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f32b5afeed9..6b131cbc5fc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-03-09 Jakub Jelinek + 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 index 00000000000..9d344fd9147 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr88568.C @@ -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]; +} -- 2.30.2