On 05/09/2016 08:45 AM, Marek Polacek wrote:
In this PR, Richi pointed out that we don't warn for the case when a
declaration with attribute optimize follows the definition which is lacking
that attribute.  This patch adds such a warning.  Though the question is
whether this shouldn't apply to more attributes than just "optimize".  And,
as can be seen in the testcase, we'll warn for even for the case when the
definition has
   optimize ("no-associative-math,O2")
and the declaration
   optimize ("O2,no-associative-math")
Not sure if we have something better than attribute_value_equal, though.

There is attribute_list_equal which seems more appropriate given
that there could be more than one attribute optimize associated
with a function, and the order of the attributes shouldn't matter.
attribute_value_equal only returns true if all attributes are
the same and in the same order.  I would not expect GCC to warn
on the following, for example:

  int attribute__ ((optimize ("no-reciprocal-math"),
                    optimize ("no-associative-math")))
  f () { return 0; }

  int __attribute__ ((optimize ("no-associative-math"),
                      optimize ("no-reciprocal-math")))
  f ();

Martin

Reply via email to