aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2016-05-10 10:22:16 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2016-05-10 10:22:16 +0000
commitcf68d92c7bb339d89426558cae2ad731ae8f0508 (patch)
tree2484ab32479d623f763dc2a8064fdd7d61b77910 /gcc
parentbf1abda157fc40b9020da82ea35c087f2a442a95 (diff)
downloadgcc-cf68d92c7bb339d89426558cae2ad731ae8f0508.zip
gcc-cf68d92c7bb339d89426558cae2ad731ae8f0508.tar.gz
gcc-cf68d92c7bb339d89426558cae2ad731ae8f0508.tar.bz2
re PR c/70255 (change of the order of summation of floating point numbers despite no-associative-math)
PR c/70255 * c-decl.c (diagnose_mismatched_decls): Warn for optimize attribute on a declaration following the definition. * gcc.dg/attr-opt-1.c: New test. From-SVN: r236071
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-decl.c12
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/attr-opt-1.c37
4 files changed, 60 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 49c9064..9387c73 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+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,
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 7094efc..9c09536 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -2228,6 +2228,18 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
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)))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 08392c7..4f3cc5d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/gcc.dg/attr-opt-1.c b/gcc/testsuite/gcc.dg/attr-opt-1.c
new file mode 100644
index 0000000..4140fda
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/attr-opt-1.c
@@ -0,0 +1,37 @@
+/* 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);