diff options
author | austern <austern@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-12-10 06:34:46 +0000 |
---|---|---|
committer | austern <austern@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-12-10 06:34:46 +0000 |
commit | 503333487efc28f86117110f890daaafebd1eb72 (patch) | |
tree | e430472ee9dc43efc31173fbf8f2e7bc2d14a17c | |
parent | e6f0a1a70a8cdb5b82f274e23f522020ec39bb6b (diff) | |
download | gcc-503333487efc28f86117110f890daaafebd1eb72.tar.gz |
PR c/13134
* c--decl.c (duplicate_decls): Copy visibility flag when appropriate.
* cp/decl.c (duplicate_decls): Copy visibility flag when appropriate.
* testsuite/lib/gcc-dg.exp (dg-require-visibility): Define.
* testsuite/lib/target-supports (check_visibility_available): Define.
* testsuite/gcc.dg/visibility-1.c: New test.
* testsuite/gcc.dg/visibility-2.c: Likewise.
* testsuite/gcc.dg/visibility-3.c: Likewise.
* testsuite/gcc.dg/visibility-4.c: Likewise.
* testsuite/gcc.dg/visibility-5.c: Likewise.
* testsuite/gcc.dg/visibility-6.c: Likewise.
* testsuite/g++.dg/ext/visibility-1.C: Likewise.
* testsuite/g++.dg/ext/visibility-2.C: Likewise.
* testsuite/g++.dg/ext/visibility-3.C: Likewise.
* testsuite/g++.dg/ext/visibility-4.C: Likewise.
* testsuite/g++.dg/ext/visibility-5.C: Likewise.
* testsuite/g++.dg/ext/visibility-6.C: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@74487 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-decl.c | 13 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-1.C | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-2.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-3.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-4.C | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-5.C | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-6.C | 10 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/visibility-7.C | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-1.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-2.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-3.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-4.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-5.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-6.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/visibility-7.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/lib/gcc-dg.exp | 17 | ||||
-rw-r--r-- | gcc/testsuite/lib/target-supports.exp | 24 |
21 files changed, 229 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c54a4fe6630..f1b73f6afc9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2003-12-09 Matt Austern <austern@apple.com> + + PR c/13134 + * c-decl.c (duplicate_decls): Copy visibility flag when appropriate. + 2003-12-09 Kazuhiro Inaoka <inaoka.kazuhiro@renesas.com> * config/m32r/m32r.h: Add support for m32r2 processor. Including diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 16cf655b8b4..8fc1f193100 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1335,6 +1335,19 @@ duplicate_decls (tree newdecl, tree olddecl, int different_binding_level, Currently, it can only be defined in the prototype. */ COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); + /* If either declaration has a nondefault visibility, use it. */ + if (DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT) + { + if (DECL_VISIBILITY (newdecl) != VISIBILITY_DEFAULT + && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) + { + warning ("%J'%D': visibility attribute ignored because it", + newdecl, newdecl); + warning ("%Jconflicts with previous declaration here", olddecl); + } + DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); + } + if (TREE_CODE (newdecl) == FUNCTION_DECL) { DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7f23f0fe435..b9a0638e25f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2003-12-08 Matt Austern <austern@apple.com> + + PR c/13134 + * decl.c (duplicate_decls): Copy visibility flag when appropriate. + 2003-12-09 Giovanni Bajo <giovannibajo@gcc.gnu.org>
* init.c (build_new_1): Deal with an OVERLOAD set when
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9c6379fa4b2..f205f7459a0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1854,9 +1854,21 @@ duplicate_decls (tree newdecl, tree olddecl) TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); DECL_COMMON (newdecl) = DECL_COMMON (olddecl); - DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl); + /* If either declaration has a nondefault visibility, use it. */ + if (DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT) + { + if (DECL_VISIBILITY (newdecl) != VISIBILITY_DEFAULT + && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) + { + warning ("%J'%D': visibility attribute ignored because it", + newdecl, newdecl); + warning ("%Jconflicts with previous declaration here", olddecl); + } + DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl); + } + if (TREE_CODE (newdecl) == FUNCTION_DECL) { int function_size; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 09784c00f2b..78e4a7d75f9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,21 @@ +2003-12-08 Matt Austern <austern@apple.com> + + PR c/13134 + * lib/gcc-dg.exp (dg-require-visibility): Define. + * lib/target-supports (check_visibility_available): Define. + * gcc.dg/visibility-1.c: New test. + * gcc.dg/visibility-2.c: Likewise. + * gcc.dg/visibility-3.c: Likewise. + * gcc.dg/visibility-4.c: Likewise. + * gcc.dg/visibility-5.c: Likewise. + * gcc.dg/visibility-6.c: Likewise. + * g++.dg/ext/visibility-1.C: Likewise. + * g++.dg/ext/visibility-2.C: Likewise. + * g++.dg/ext/visibility-3.C: Likewise. + * g++.dg/ext/visibility-4.C: Likewise. + * g++.dg/ext/visibility-5.C: Likewise. + * g++.dg/ext/visibility-6.C: Likewise. + 2003-12-07 Giovanni Bajo <giovannibajo@gcc.gnu.org>
* g++.dg/lookup/java1.C: New test.
diff --git a/gcc/testsuite/g++.dg/ext/visibility-1.C b/gcc/testsuite/g++.dg/ext/visibility-1.C new file mode 100644 index 00000000000..d579eb27206 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-1.C @@ -0,0 +1,8 @@ +/* Test visibility attribute on function definition. */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */ + +void +__attribute__((visibility ("hidden"))) +foo() +{ } diff --git a/gcc/testsuite/g++.dg/ext/visibility-2.C b/gcc/testsuite/g++.dg/ext/visibility-2.C new file mode 100644 index 00000000000..89e853c4dc5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-2.C @@ -0,0 +1,7 @@ +/* Test that visibility attribute on declaration extends to definition. */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */ + +void __attribute__((visibility ("hidden"))) foo(); + +void foo() { } diff --git a/gcc/testsuite/g++.dg/ext/visibility-3.C b/gcc/testsuite/g++.dg/ext/visibility-3.C new file mode 100644 index 00000000000..d0cc8912efb --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-3.C @@ -0,0 +1,7 @@ +/* Test visibility attribute on forward declaration of global variable */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +int +__attribute__((visibility ("hidden"))) +xyzzy = 5; diff --git a/gcc/testsuite/g++.dg/ext/visibility-4.C b/gcc/testsuite/g++.dg/ext/visibility-4.C new file mode 100644 index 00000000000..d217bc9ec5d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-4.C @@ -0,0 +1,8 @@ +/* Test visibility attribute on forward declaration of global variable */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int __attribute__ ((visibility ("hidden"))) +xyzzy; + +int xyzzy = 5; diff --git a/gcc/testsuite/g++.dg/ext/visibility-5.C b/gcc/testsuite/g++.dg/ext/visibility-5.C new file mode 100644 index 00000000000..9cdc8021e47 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-5.C @@ -0,0 +1,11 @@ +/* Test visibility attribute on definition of a function that has + already had a forward declaration. */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */ + +void foo(); + +void + __attribute__((visibility ("hidden"))) +foo() +{ } diff --git a/gcc/testsuite/g++.dg/ext/visibility-6.C b/gcc/testsuite/g++.dg/ext/visibility-6.C new file mode 100644 index 00000000000..6e8f0ce1135 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-6.C @@ -0,0 +1,10 @@ +/* Test visibility attribute on definition of global variable that has + already had a forward declaration. */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int xyzzy; + +int +__attribute__((visibility ("hidden"))) +xyzzy = 5; diff --git a/gcc/testsuite/g++.dg/ext/visibility-7.C b/gcc/testsuite/g++.dg/ext/visibility-7.C new file mode 100644 index 00000000000..40acb72463f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility-7.C @@ -0,0 +1,11 @@ +/* Test warning from conflicting visibility specifications. */ +/* { dg-do compile { target *86-*-linux* } } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int +__attribute__((visibility ("hidden"))) +xyzzy; /* { dg-warning "previous declaration here" "" } */ + +int +__attribute__((visibility ("protected"))) +xyzzy = 5; /* { dg-warning "visibility attribute ignored" "" } */ diff --git a/gcc/testsuite/gcc.dg/visibility-1.c b/gcc/testsuite/gcc.dg/visibility-1.c new file mode 100644 index 00000000000..f76c3ca9154 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-1.c @@ -0,0 +1,9 @@ +/* Test visibility attribute on function definition. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*foo" } } */ + +void +__attribute__((visibility ("hidden"))) +foo() +{ } diff --git a/gcc/testsuite/gcc.dg/visibility-2.c b/gcc/testsuite/gcc.dg/visibility-2.c new file mode 100644 index 00000000000..e62dbbb4cd5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-2.c @@ -0,0 +1,10 @@ +/* Test that visibility attribute on declaration extends to definition. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*foo" } } */ + +void +__attribute__((visibility ("hidden"))) +foo(); + +void foo() { } diff --git a/gcc/testsuite/gcc.dg/visibility-3.c b/gcc/testsuite/gcc.dg/visibility-3.c new file mode 100644 index 00000000000..e0bf01fb130 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-3.c @@ -0,0 +1,8 @@ +/* Test visibility attribute on forward declaration of global variable */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +int +__attribute__((visibility ("hidden"))) +xyzzy = 5; diff --git a/gcc/testsuite/gcc.dg/visibility-4.c b/gcc/testsuite/gcc.dg/visibility-4.c new file mode 100644 index 00000000000..1a0b3ca37da --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-4.c @@ -0,0 +1,10 @@ +/* Test visibility attribute on forward declaration of global variable */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int +__attribute__((visibility ("hidden"))) +xyzzy; + +int xyzzy = 5; diff --git a/gcc/testsuite/gcc.dg/visibility-5.c b/gcc/testsuite/gcc.dg/visibility-5.c new file mode 100644 index 00000000000..b1f46d2040a --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-5.c @@ -0,0 +1,12 @@ +/* Test visibility attribute on definition of a function that has + already had a forward declaration. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*foo" } } */ + +void foo(); + +void + __attribute__((visibility ("hidden"))) +foo() +{ } diff --git a/gcc/testsuite/gcc.dg/visibility-6.c b/gcc/testsuite/gcc.dg/visibility-6.c new file mode 100644 index 00000000000..632f2ac2059 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-6.c @@ -0,0 +1,11 @@ +/* Test visibility attribute on definition of global variable that has + already had a forward declaration. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int xyzzy; + +int +__attribute__((visibility ("hidden"))) +xyzzy = 5; diff --git a/gcc/testsuite/gcc.dg/visibility-7.c b/gcc/testsuite/gcc.dg/visibility-7.c new file mode 100644 index 00000000000..e98b432c827 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-7.c @@ -0,0 +1,12 @@ +/* Test warning from conflicting visibility specifications. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-assembler "\\.hidden.*xyzzy" } } */ + +extern int +__attribute__((visibility ("hidden"))) +xyzzy; /* { dg-warning "previous declaration here" "" } */ + +int +__attribute__((visibility ("protected"))) +xyzzy = 5; /* { dg-warning "visibility attribute ignored" "" } */ diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index ee1d4d84a64..7fd52a94867 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -267,6 +267,23 @@ proc dg-require-weak { args } { } } +# If this target does not support the "visibility" attribute, skip this +# test. + +proc dg-require-visibility { args } { + upvar dg-do-what dg-do-what + upvar name name + + set visibility_available [ check_visibility_available ] + if { $visibility_available == -1 } { + unresolved "$name" + } + if { $visibility_available != 1 } { + set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"] + return + } +} + # If this target does not support the "alias" attribute, skip this # test. diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 38d416ccb77..e9a57a1b7c2 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -63,6 +63,30 @@ proc check_weak_available { } { } ############################### +# proc check_visibility_available { } +############################### + +# The visibility attribute is only support in some object formats +# This proc returns 1 if it is supported, 0 if not, -1 if unsure. + +proc check_visibility_available { } { + global target_triplet + global target_cpu + + # ELF supports it if the system has recent GNU ld and gas. + # As a start we return 1 for all ELF systems; we'll let people + # add exceptions as necessary. + + set objformat [gcc_target_object_format] + + switch $objformat { + elf { return 1 } + unknown { return -1 } + default { return 0 } + } +} + +############################### # proc check_alias_available { } ############################### |