This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH to use is_global_var
- From: Marek Polacek <polacek at redhat dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 25 Jun 2015 14:44:17 +0200
- Subject: Re: C PATCH to use is_global_var
- Authentication-results: sourceware.org; auth=none
- References: <20150624102245 dot GV10139 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1506241715000 dot 6710 at digraph dot polyomino dot org dot uk>
On Wed, Jun 24, 2015 at 05:16:33PM +0000, Joseph Myers wrote:
> On Wed, 24 Jun 2015, Marek Polacek wrote:
>
> > diff --git gcc/c/c-decl.c gcc/c/c-decl.c
> > index fc1fdf9..ab54db9 100644
> > --- gcc/c/c-decl.c
> > +++ gcc/c/c-decl.c
> > @@ -2650,9 +2650,8 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
> > tree_code_size (TREE_CODE (olddecl)) - sizeof (struct tree_decl_common));
> > olddecl->decl_with_vis.symtab_node = snode;
> >
> > - if ((DECL_EXTERNAL (olddecl)
> > - || TREE_PUBLIC (olddecl)
> > - || TREE_STATIC (olddecl))
> > + if ((is_global_var (olddecl)
> > + || TREE_PUBLIC (olddecl))
> > && DECL_SECTION_NAME (newdecl) != NULL)
> > set_decl_section_name (olddecl, DECL_SECTION_NAME (newdecl));
> >
>
> At least this case covers both FUNCTION_DECL and VAR_DECL. If
> is_global_var is appropriate for functions as well as variables, I think
> it should be renamed (and have its comment updated to explain what it
> means for functions).
You raise a good point. After fair amount of investigating, I don't think
is_global_var is appropriate for functions. (DECL_EXTERNAL || TREE_STATIC)
for a function is only false for weird cases such as an inline function
definition followed by redeclaring this function with noinline attribute, i.e.:
inline void a (void) {}
void a (void) __attribute__ ((noinline));
void
b ()
{
a ();
}
is_global_var with a FUNCTION_DECL is only called in tree-ssa-structalias.c
and it seems like a mistake.
So I propose to commit the following patch, which uses is_global_var only
at places where we're dealing with a variable.
Ok for trunk?
2015-06-25 Marek Polacek <polacek@redhat.com>
* cilk.c (extract_free_variables): Use is_global_var.
* c-decl.c: Use is_global_var throughout.
* c-parser.c: Likewise.
* c-typeck.c: Likewise.
diff --git gcc/c-family/cilk.c gcc/c-family/cilk.c
index c38e05f..347e4b9 100644
--- gcc/c-family/cilk.c
+++ gcc/c-family/cilk.c
@@ -1063,7 +1063,7 @@ extract_free_variables (tree t, struct wrapper_data *wd,
TREE_ADDRESSABLE (t) = 1;
case VAR_DECL:
case PARM_DECL:
- if (!TREE_STATIC (t) && !DECL_EXTERNAL (t))
+ if (!is_global_var (t))
add_variable (wd, t, how);
return;
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index fc1fdf9..ab54db9 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -4395,7 +4394,7 @@ c_decl_attributes (tree *node, tree attributes, int flags)
/* Add implicit "omp declare target" attribute if requested. */
if (current_omp_declare_target_attribute
&& ((TREE_CODE (*node) == VAR_DECL
- && (TREE_STATIC (*node) || DECL_EXTERNAL (*node)))
+ && is_global_var (*node))
|| TREE_CODE (*node) == FUNCTION_DECL))
{
if (TREE_CODE (*node) == VAR_DECL
@@ -4794,8 +4793,7 @@ finish_decl (tree decl, location_t init_loc, tree init,
TREE_TYPE (decl) = error_mark_node;
}
- if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
- && DECL_SIZE (decl) != 0)
+ if (is_global_var (decl) && DECL_SIZE (decl) != 0)
{
if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
constant_expression_warning (DECL_SIZE (decl));
@@ -4911,8 +4909,7 @@ finish_decl (tree decl, location_t init_loc, tree init,
{
/* Recompute the RTL of a local array now
if it used to be an incomplete type. */
- if (was_incomplete
- && !TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
+ if (was_incomplete && !is_global_var (decl))
{
/* If we used it already as memory, it must stay in memory. */
TREE_ADDRESSABLE (decl) = TREE_USED (decl);
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index e0ab0a1..f4d18bd 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -14769,7 +14769,7 @@ c_parser_omp_threadprivate (c_parser *parser)
error_at (loc, "%qD is not a variable", v);
else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
error_at (loc, "%qE declared %<threadprivate%> after first use", v);
- else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
+ else if (! is_global_var (v))
error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v);
else if (TREE_TYPE (v) == error_mark_node)
;
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index aeb1043..3dc1f07 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -4380,7 +4380,7 @@ c_mark_addressable (tree exp)
if (C_DECL_REGISTER (x)
&& DECL_NONLOCAL (x))
{
- if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
+ if (TREE_PUBLIC (x) || is_global_var (x))
{
error
("global register variable %qD used in nested function", x);
@@ -4390,7 +4390,7 @@ c_mark_addressable (tree exp)
}
else if (C_DECL_REGISTER (x))
{
- if (TREE_PUBLIC (x) || TREE_STATIC (x) || DECL_EXTERNAL (x))
+ if (TREE_PUBLIC (x) || is_global_var (x))
error ("address of global register variable %qD requested", x);
else
error ("address of register variable %qD requested", x);