+2016-05-10 Marek Polacek <polacek@redhat.com>
+
+ PR c/70255
+ * c-decl.c (diagnose_mismatched_decls): Warn for optimize attribute
+ on a declaration following the definition.
+
2016-05-05 Jakub Jelinek <jakub@redhat.com>
* c-parser.c (c_parser_switch_statement): Add IF_P argument,
if (TREE_CODE (newdecl) == FUNCTION_DECL)
{
+ tree a1 = lookup_attribute ("optimize", DECL_ATTRIBUTES (olddecl));
+ tree a2 = lookup_attribute ("optimize", DECL_ATTRIBUTES (newdecl));
+ /* An optimization attribute applied on a declaration after the
+ definition is likely not what the user wanted. */
+ if (a2 != NULL_TREE
+ && DECL_SAVED_TREE (olddecl) != NULL_TREE
+ && (a1 == NULL_TREE || !attribute_list_equal (a1, a2)))
+ warned |= warning (OPT_Wattributes,
+ "optimization attribute on %qD follows "
+ "definition but the attribute doesn%'t match",
+ newdecl);
+
/* Diagnose inline __attribute__ ((noinline)) which is silly. */
if (DECL_DECLARED_INLINE_P (newdecl)
&& lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl)))
+2016-05-10 Marek Polacek <polacek@redhat.com>
+
+ PR c/70255
+ * gcc.dg/attr-opt-1.c: New test.
+
2016-05-10 Richard Biener <rguenther@suse.de>
PR tree-optimization/70497
--- /dev/null
+/* PR c/70255 */
+/* { dg-do compile } */
+
+double
+fn1 (double h, double l) /* { dg-message "previous definition" } */
+{
+ return h + l;
+}
+double fn1 (double, double) __attribute__ ((optimize ("no-associative-math"))); /* { dg-warning "optimization attribute on .fn1. follows definition" } */
+
+__attribute__ ((optimize ("no-associative-math"))) double
+fn2 (double h, double l)
+{
+ return h + l;
+}
+double fn2 (double, double) __attribute__ ((optimize ("no-associative-math")));
+
+__attribute__ ((optimize ("no-associative-math"))) double
+fn3 (double h, double l) /* { dg-message "previous definition" } */
+{
+ return h + l;
+}
+double fn3 (double, double) __attribute__ ((optimize ("O2,no-associative-math"))); /* { dg-warning "optimization attribute on .fn3. follows definition" } */
+
+__attribute__ ((optimize ("no-associative-math,O2"))) double
+fn4 (double h, double l) /* { dg-message "previous definition" } */
+{
+ return h + l;
+}
+double fn4 (double, double) __attribute__ ((optimize ("O2,no-associative-math"))); /* { dg-warning "optimization attribute on .fn4. follows definition" } */
+
+__attribute__ ((optimize ("no-reciprocal-math"), optimize ("no-associative-math"))) int
+fn5 (void)
+{
+ return 0;
+}
+int __attribute__ ((optimize ("no-associative-math"), optimize ("no-reciprocal-math"))) fn5 (void);