re PR c/28744 (externally_visible attribute not effective with prior declaration of symbol.)

PR c/28744
	* cgraph.h (struct cgraph_node): Remove externally_visible
	bitfield.
	* cgraphunit.c (process_function_and_variable_attributes): Set
	local.externally_visible rather than externally_visible.

	PR c/28744
	* c-common.c (handle_externally_visible_attribute): First look
	at TREE_CODE and only if it is function or var decl, check for
	non-public objects.  Don't warn for DECL_EXTERNAL.
	* cgraphunit.c (process_function_and_variable_attributes): Warn
	if externally_visible attribute is used on non-public object.

	* gcc.dg/attr-externally-visible-1.c: New test.
	* gcc.dg/attr-externally-visible-2.c: New test.
	* g++.dg/parse/attr-externally-visible-1.C: New test.
	* g++.dg/parse/attr-externally-visible-2.C: New test.

From-SVN: r116222
This commit is contained in:
Jakub Jelinek 2006-08-17 13:52:26 +02:00 committed by Jakub Jelinek
parent 7ffaaddcda
commit 343d4b27bf
9 changed files with 218 additions and 16 deletions

View file

@ -1,3 +1,18 @@
2006-08-17 Jakub Jelinek <jakub@redhat.com>
PR c/28744
* cgraph.h (struct cgraph_node): Remove externally_visible
bitfield.
* cgraphunit.c (process_function_and_variable_attributes): Set
local.externally_visible rather than externally_visible.
PR c/28744
* c-common.c (handle_externally_visible_attribute): First look
at TREE_CODE and only if it is function or var decl, check for
non-public objects. Don't warn for DECL_EXTERNAL.
* cgraphunit.c (process_function_and_variable_attributes): Warn
if externally_visible attribute is used on non-public object.
2006-08-17 Jan Hubicka <jh@suse.cz>
PR tree-optimization/27865

View file

@ -4301,16 +4301,16 @@ handle_externally_visible_attribute (tree *pnode, tree name,
{
tree node = *pnode;
if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL)
|| !TREE_PUBLIC (node))
if (TREE_CODE (node) == FUNCTION_DECL || TREE_CODE (node) == VAR_DECL)
{
warning (OPT_Wattributes,
"%qE attribute have effect only on public objects", name);
*no_add_attrs = true;
if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
&& !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
{
warning (OPT_Wattributes,
"%qE attribute have effect only on public objects", name);
*no_add_attrs = true;
}
}
else if (TREE_CODE (node) == FUNCTION_DECL
|| TREE_CODE (node) == VAR_DECL)
;
else
{
warning (OPT_Wattributes, "%qE attribute ignored", name);

View file

@ -160,8 +160,6 @@ struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
unsigned analyzed : 1;
/* Set when function is scheduled to be assembled. */
unsigned output : 1;
/* Set when function is visible by other units. */
unsigned externally_visible : 1;
/* Set for aliases once they got through assemble_alias. */
unsigned alias : 1;

View file

@ -985,9 +985,16 @@ process_function_and_variable_attributes (struct cgraph_node *first,
}
if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
{
if (node->local.finalized)
cgraph_mark_needed_node (node);
node->externally_visible = true;
if (! TREE_PUBLIC (node->decl))
warning (OPT_Wattributes,
"%J%<externally_visible%> attribute have effect only on public objects",
node->decl);
else
{
if (node->local.finalized)
cgraph_mark_needed_node (node);
node->local.externally_visible = true;
}
}
}
for (vnode = cgraph_varpool_nodes; vnode != first_var; vnode = vnode->next)
@ -1001,9 +1008,16 @@ process_function_and_variable_attributes (struct cgraph_node *first,
}
if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl)))
{
if (vnode->finalized)
cgraph_varpool_mark_needed_node (vnode);
vnode->externally_visible = true;
if (! TREE_PUBLIC (vnode->decl))
warning (OPT_Wattributes,
"%J%<externally_visible%> attribute have effect only on public objects",
vnode->decl);
else
{
if (vnode->finalized)
cgraph_varpool_mark_needed_node (vnode);
vnode->externally_visible = true;
}
}
}
}

View file

@ -1,3 +1,11 @@
2006-08-17 Jakub Jelinek <jakub@redhat.com>
PR c/28744
* gcc.dg/attr-externally-visible-1.c: New test.
* gcc.dg/attr-externally-visible-2.c: New test.
* g++.dg/parse/attr-externally-visible-1.C: New test.
* g++.dg/parse/attr-externally-visible-2.C: New test.
2006-08-17 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28606

View file

@ -0,0 +1,48 @@
// { dg-do compile }
// { dg-options "-O3 -fwhole-program" }
// { dg-final { scan-assembler "foo1" } }
// { dg-final { scan-assembler "foo2" } }
// { dg-final { scan-assembler "foo3" } }
// { dg-final { scan-assembler "foo4" } }
// { dg-final { scan-assembler "foo5" } }
// { dg-final { scan-assembler-not "foo6" } }
// { dg-final { scan-assembler "bar1" } }
// { dg-final { scan-assembler "bar2" } }
// { dg-final { scan-assembler "bar3" } }
// { dg-final { scan-assembler "bar4" } }
// { dg-final { scan-assembler "bar5" } }
// { dg-final { scan-assembler-not "bar6" } }
extern void foo1 (void) __attribute__((externally_visible));
void foo1 (void) { }
extern void foo2 (void) __attribute__((externally_visible));
__attribute__((externally_visible)) void foo2 (void) { }
extern void foo3 (void);
__attribute__((externally_visible)) void foo3 (void) { }
__attribute__((externally_visible)) void foo4 (void) { }
void foo5 (void) { }
extern void foo5 (void) __attribute__((externally_visible));
void foo6 (void) { }
extern char *bar1 __attribute__((externally_visible));
char *bar1;
extern char *bar2 __attribute__((externally_visible));
char *bar2 __attribute__((externally_visible));
extern char *bar3;
char *bar3 __attribute__((externally_visible));
char *bar4 __attribute__((externally_visible));
char *bar5;
extern char *bar5 __attribute__((externally_visible));
char *bar6;
int main (void) { }

View file

@ -0,0 +1,38 @@
// { dg-do compile }
// { dg-options "-O -fwhole-program" }
static void foo1 (void) { } // { dg-warning "have effect only on public" }
extern void foo1 (void) __attribute__((externally_visible));
struct C
{
__attribute__((externally_visible)) void foo3 (void) { }
};
__attribute__((externally_visible)) static void foo3 (void) { } // { dg-warning "have effect only on public" }
static int bar1;
extern int bar1 __attribute__((externally_visible)); // { dg-warning "have effect only on public" }
static int bar2 __attribute__((externally_visible)); // { dg-warning "have effect only on public" }
void fn1 (void)
{
static int bar3 __attribute__((externally_visible)); // { dg-warning "have effect only on public" }
}
void fn2 (void)
{
int bar4 __attribute__((externally_visible)); // { dg-warning "have effect only on public" }
}
struct A
{
} __attribute__((externally_visible)); // { dg-warning "does not apply to types" }
typedef int B __attribute__((externally_visible)); // { dg-warning "attribute ignored" }
struct D
{
static int d __attribute__((externally_visible));
};

View file

@ -0,0 +1,48 @@
/* { dg-do compile } */
/* { dg-options "-O3 -fwhole-program" } */
/* { dg-final { scan-assembler "foo1" } } */
/* { dg-final { scan-assembler "foo2" } } */
/* { dg-final { scan-assembler "foo3" } } */
/* { dg-final { scan-assembler "foo4" } } */
/* { dg-final { scan-assembler "foo5" } } */
/* { dg-final { scan-assembler-not "foo6" } } */
/* { dg-final { scan-assembler "bar1" } } */
/* { dg-final { scan-assembler "bar2" } } */
/* { dg-final { scan-assembler "bar3" } } */
/* { dg-final { scan-assembler "bar4" } } */
/* { dg-final { scan-assembler "bar5" } } */
/* { dg-final { scan-assembler-not "bar6" } } */
extern void foo1 (void) __attribute__((externally_visible));
void foo1 (void) { }
extern void foo2 (void) __attribute__((externally_visible));
__attribute__((externally_visible)) void foo2 (void) { }
extern void foo3 (void);
__attribute__((externally_visible)) void foo3 (void) { }
__attribute__((externally_visible)) void foo4 (void) { }
void foo5 (void) { }
extern void foo5 (void) __attribute__((externally_visible));
void foo6 (void) { }
extern char *bar1 __attribute__((externally_visible));
char *bar1;
extern char *bar2 __attribute__((externally_visible));
char *bar2 __attribute__((externally_visible));
extern char *bar3;
char *bar3 __attribute__((externally_visible));
char *bar4 __attribute__((externally_visible));
char *bar5;
extern char *bar5 __attribute__((externally_visible));
char *bar6;
int main (void) { }

View file

@ -0,0 +1,33 @@
/* { dg-do compile } */
/* { dg-options "-O -fwhole-program" } */
static void foo1 (void) { } /* { dg-warning "have effect only on public" } */
extern void foo1 (void) __attribute__((externally_visible));
void foo2 (void)
{
__attribute__((externally_visible)) void foo3 (void) { } /* { dg-warning "have effect only on public" } */
}
__attribute__((externally_visible)) static void foo3 (void) { } /* { dg-warning "have effect only on public" } */
static int bar1;
extern int bar1 __attribute__((externally_visible)); /* { dg-warning "have effect only on public" } */
static int bar2 __attribute__((externally_visible)); /* { dg-warning "have effect only on public" } */
void fn1 (void)
{
static int bar3 __attribute__((externally_visible)); /* { dg-warning "have effect only on public" } */
}
void fn2 (void)
{
int bar4 __attribute__((externally_visible)); /* { dg-warning "have effect only on public" } */
}
struct A
{
} __attribute__((externally_visible)); /* { dg-warning "does not apply to types" } */
typedef int B __attribute__((externally_visible)); /* { dg-warning "attribute ignored" } */