Commit facef326 by Matt Austern Committed by Matt Austern

re PR c/13134 (Visibility attribute is ignored)

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.

From-SVN: r74487
parent 5ec3f566
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
......
......@@ -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);
......
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
......
......@@ -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;
......
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.
......
/* Test visibility attribute on function definition. */
/* { dg-do compile { target *86-*-linux* } } */
/* { dg-final { scan-assembler "\\.hidden.*_Z3foov" } } */
void
__attribute__((visibility ("hidden")))
foo()
{ }
/* 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() { }
/* 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;
/* 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;
/* 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()
{ }
/* 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;
/* 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" "" } */
/* Test visibility attribute on function definition. */
/* { dg-do compile } */
/* { dg-require-visibility "" } */
/* { dg-final { scan-assembler "\\.hidden.*foo" } } */
void
__attribute__((visibility ("hidden")))
foo()
{ }
/* 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() { }
/* 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;
/* 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;
/* 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()
{ }
/* 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;
/* 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" "" } */
......@@ -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.
......
......@@ -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 { }
###############################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment