diff options
author | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-05-10 10:22:16 +0000 |
---|---|---|
committer | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-05-10 10:22:16 +0000 |
commit | 3fa82609676e4eec8847414daf02a68cbfcbc7f0 (patch) | |
tree | 2484ab32479d623f763dc2a8064fdd7d61b77910 /gcc/c/c-decl.c | |
parent | 6da0ac8390a5d0518435a68c11864b075030e24f (diff) | |
download | gcc-3fa82609676e4eec8847414daf02a68cbfcbc7f0.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236071 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c/c-decl.c')
-rw-r--r-- | gcc/c/c-decl.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 7094efc5dfe..9c09536c18e 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))) |