While going through the attribute tables to sort out separation or trees
and types, I'm seeing a couple of ports with similar handlers that look
a little odd.
the code sequence in the handler looks like:
if (TREE_CODE (*node) != VAR_DECL
&& TREE_CODE (*node) != POINTER_TYPE
&& TREE_CODE (*node) != TYPE_DECL)
{
warning (OPT_Wattributes,
"%<__BELOW100__%> attribute only applies to variables");
*no_add_attrs = true;
}
My question is
a) what is POINTER_TYPE doing in there.. what has that got to do with
applying to variables, and
b) should TYPE_DECL also be there?
I can almost see the argument for b).... MAYBE, but then the message
doesn't really make sense. but POINTER_TYPE seems really odd.
so ports that use that message:
avr, bfin, x86: handlers all make sure its *ONLY* a VAR_DECL handled
mep, stormy16 : uses the suspect sequence. My guess is one copied the
other.
In fact, the mep port does have a couple of other handlers that check
for only VAR_DECL associated with that warning.
mep also has another handler for "variable and functions" that looks like:
if (TREE_CODE (*node) != VAR_DECL
&& TREE_CODE (*node) != FUNCTION_DECL
&& TREE_CODE (*node) != METHOD_TYPE
&& TREE_CODE (*node) != POINTER_TYPE
&& TREE_CODE (*node) != TYPE_DECL)
{
warning (0, "%qE attribute only applies to variables and functions",
name);
*no_add = true;
}
Most ports use VAR_DECL and FUNCTION_DECL for this warning. Its odd
that METHOD_TYPE is there, but not FUNCTION_TYPE if types were really
handled...
And finally, also in mep :
if (TREE_CODE (*node) != FUNCTION_DECL
&& TREE_CODE (*node) != METHOD_TYPE)
{
warning (0, "%qE attribute only applies to functions", name);
*no_add = true;
}
It doesn't seem that METHOD_TYPE should be there, unless FUNCTION_TYPE
was also important. It does have other handlers where the check is only
for FUNCTION_DECL *OR* FUNCTION_TYPE, not this odd hybrid. It's the
only port that has this.
If the handlers are ONLY going to deal with decls, the attribute table
ought to have the decl_required flag set as well, which the other ports
do, but these 2 do not.. perhaps because of the existing _TYPE handling...?
Assuming I understand this right, I've attached a patch which covers mep
and stormy16. It corrects those tables and handlers to work the way I
think they are suppose to. They build, but I cant test them... can
some with that ability run them and see if they are correct?
Assuming no one has a counter argument to what I'm saying... Maybe there
is some need for this that I'm just missing :-)
Andrew
* config/mep/mep.c (mep_validate_based_tiny): Only deal with VAR_DECL.
(mep_validate_near_far): Only allow VAR_DECL and FUNCTION_DECL.
(mep_validate_disinterrupt): Only allow FUNCTION_DECL.
(mep_attribute_table): Set decl_required field for some handlers.
* config/stormy16/stormy16.c (xstormy16_attribute_table): Set
decl_required field for below100 handler.
(xstormy16_handle_below100_attribute): Only handle VAR_DECL.
Index: config/mep/mep.c
===================================================================
*** config/mep/mep.c (revision 217822)
--- config/mep/mep.c (working copy)
*************** static tree
*** 3813,3826 ****
mep_validate_based_tiny (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
! if (TREE_CODE (*node) != VAR_DECL
! && TREE_CODE (*node) != POINTER_TYPE
! && TREE_CODE (*node) != TYPE_DECL)
{
warning (0, "%qE attribute only applies to variables", name);
*no_add = true;
}
! else if (args == NULL_TREE && TREE_CODE (*node) == VAR_DECL)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{
--- 3813,3824 ----
mep_validate_based_tiny (tree *node, tree name, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
! if (TREE_CODE (*node) != VAR_DECL)
{
warning (0, "%qE attribute only applies to variables", name);
*no_add = true;
}
! else if (args == NULL_TREE)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{
*************** mep_validate_near_far (tree *node, tree
*** 3874,3883 ****
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != VAR_DECL
! && TREE_CODE (*node) != FUNCTION_DECL
! && TREE_CODE (*node) != METHOD_TYPE
! && TREE_CODE (*node) != POINTER_TYPE
! && TREE_CODE (*node) != TYPE_DECL)
{
warning (0, "%qE attribute only applies to variables and functions",
name);
--- 3872,3878 ----
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
if (TREE_CODE (*node) != VAR_DECL
! && TREE_CODE (*node) != FUNCTION_DECL)
{
warning (0, "%qE attribute only applies to variables and functions",
name);
*************** static tree
*** 3910,3917 ****
mep_validate_disinterrupt (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
! if (TREE_CODE (*node) != FUNCTION_DECL
! && TREE_CODE (*node) != METHOD_TYPE)
{
warning (0, "%qE attribute only applies to functions", name);
*no_add = true;
--- 3905,3911 ----
mep_validate_disinterrupt (tree *node, tree name, tree args ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED, bool *no_add)
{
! if (TREE_CODE (*node) != FUNCTION_DECL)
{
warning (0, "%qE attribute only applies to functions", name);
*no_add = true;
*************** static const struct attribute_spec mep_a
*** 4032,4046 ****
{
/* name min max decl type func handler
affects_type_identity */
! { "based", 0, 0, false, false, false, mep_validate_based_tiny, false },
! { "tiny", 0, 0, false, false, false, mep_validate_based_tiny, false },
! { "near", 0, 0, false, false, false, mep_validate_near_far, false },
! { "far", 0, 0, false, false, false, mep_validate_near_far, false },
! { "disinterrupt", 0, 0, false, false, false, mep_validate_disinterrupt,
false },
! { "interrupt", 0, 0, false, false, false, mep_validate_interrupt, false },
! { "io", 0, 1, false, false, false, mep_validate_io_cb, false },
! { "cb", 0, 1, false, false, false, mep_validate_io_cb, false },
{ "vliw", 0, 0, false, true, false, mep_validate_vliw, false },
{ NULL, 0, 0, false, false, false, NULL, false }
};
--- 4026,4040 ----
{
/* name min max decl type func handler
affects_type_identity */
! { "based", 0, 0, true, false, false, mep_validate_based_tiny, false },
! { "tiny", 0, 0, true, false, false, mep_validate_based_tiny, false },
! { "near", 0, 0, true, false, false, mep_validate_near_far, false },
! { "far", 0, 0, true, false, false, mep_validate_near_far, false },
! { "disinterrupt", 0, 0, true, false, false, mep_validate_disinterrupt,
false },
! { "interrupt", 0, 0, true, false, false, mep_validate_interrupt, false },
! { "io", 0, 1, true, false, false, mep_validate_io_cb, false },
! { "cb", 0, 1, true, false, false, mep_validate_io_cb, false },
{ "vliw", 0, 0, false, true, false, mep_validate_vliw, false },
{ NULL, 0, 0, false, false, false, NULL, false }
};
Index: config/stormy16/stormy16.c
===================================================================
*** config/stormy16/stormy16.c (revision 217822)
--- config/stormy16/stormy16.c (working copy)
*************** static const struct attribute_spec xstor
*** 2216,2224 ****
affects_type_identity. */
{ "interrupt", 0, 0, false, true, true,
xstormy16_handle_interrupt_attribute , false },
! { "BELOW100", 0, 0, false, false, false,
xstormy16_handle_below100_attribute, false },
! { "below100", 0, 0, false, false, false,
xstormy16_handle_below100_attribute, false },
{ NULL, 0, 0, false, false, false, NULL, false }
};
--- 2216,2224 ----
affects_type_identity. */
{ "interrupt", 0, 0, false, true, true,
xstormy16_handle_interrupt_attribute , false },
! { "BELOW100", 0, 0, true, false, false,
xstormy16_handle_below100_attribute, false },
! { "below100", 0, 0, true, false, false,
xstormy16_handle_below100_attribute, false },
{ NULL, 0, 0, false, false, false, NULL, false }
};
*************** xstormy16_handle_below100_attribute (tre
*** 2252,2266 ****
int flags ATTRIBUTE_UNUSED,
bool *no_add_attrs)
{
! if (TREE_CODE (*node) != VAR_DECL
! && TREE_CODE (*node) != POINTER_TYPE
! && TREE_CODE (*node) != TYPE_DECL)
{
warning (OPT_Wattributes,
"%<__BELOW100__%> attribute only applies to variables");
*no_add_attrs = true;
}
! else if (args == NULL_TREE && TREE_CODE (*node) == VAR_DECL)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{
--- 2252,2264 ----
int flags ATTRIBUTE_UNUSED,
bool *no_add_attrs)
{
! if (TREE_CODE (*node) != VAR_DECL)
{
warning (OPT_Wattributes,
"%<__BELOW100__%> attribute only applies to variables");
*no_add_attrs = true;
}
! else if (args == NULL_TREE)
{
if (! (TREE_PUBLIC (*node) || TREE_STATIC (*node)))
{