From patchwork Thu Mar 20 14:44:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 332200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C45DD2C0082 for ; Fri, 21 Mar 2014 01:44:40 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=xuLPLbSQMqflZu20t 5+hjKH30NmDSxKa08OOOnwVTspMk3tPzPqMnUmWrDx95DNlDeZpcjmeiQoUAAXrh Vc3t03MhZxylZCPSkolqQe7mijdsn3Fa6kmi9cCFqs00tU6oC017tE4LjWK6OEpp TDeDjauLYeJGA6wzrcPB9Vz5c8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=7OZEK67nPSEjyM6uoP2fkOz LKQQ=; b=mRQnOV0bGoD6TbHmxMugoHSaOFmuWARtFL6MIsppR4TvWOX2SFUIIW1 mC1SiEh23avX4OnoU8XrF0nIWXpnLRqJsiZtei5PK00dlxBDvCAzaDQfsul7z5Nz JCFpnCECWn6WJD1i46A8jRdSeThVKxlRSZEsM66uhCG6koJNChRo= Received: (qmail 3976 invoked by alias); 20 Mar 2014 14:44:34 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3966 invoked by uid 89); 20 Mar 2014 14:44:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Mar 2014 14:44:32 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2KEiSmg020642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Mar 2014 10:44:29 -0400 Received: from redhat.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s2KEiObI012180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 20 Mar 2014 10:44:27 -0400 Date: Thu, 20 Mar 2014 15:44:24 +0100 From: Marek Polacek To: "Joseph S. Myers" Cc: Richard Biener , GCC Patches Subject: Re: [C PATCH] Warn if inline attributes conflict (PR c/18079) Message-ID: <20140320144423.GN6523@redhat.com> References: <20140320110736.GL6523@redhat.com> <20140320114552.GM6523@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) On Thu, Mar 20, 2014 at 11:57:57AM +0000, Joseph S. Myers wrote: > This version is OK (for after 4.9 branches). Thanks. > What happens if there are two declarations of the function, one with each > attribute? The testcase doesn't cover that. Nothing :(. I had to add some code into diagnose_mismatched_decls to detect such conflicting decls (plus for cold/hot; there may be others). Tested x86_64-linux. Is this version ok? 2014-03-20 Marek Polacek PR c/18079 c/ * c-decl.c (diagnose_mismatched_decls): Warn for mismatched always_inline/noinline and hot/cold attributes. c-family/ * c-common.c (handle_noinline_attribute): Warn if the attribute conflicts with always_inline attribute. (handle_always_inline_attribute): Warn if the attribute conflicts with noinline attribute. testsuite/ * gcc.dg/pr18079.c: New test. * gcc.dg/pr18079-2.c: New test. Marek diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index abd96fb..5258e52 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -6666,7 +6666,16 @@ handle_noinline_attribute (tree *node, tree name, int ARG_UNUSED (flags), bool *no_add_attrs) { if (TREE_CODE (*node) == FUNCTION_DECL) - DECL_UNINLINABLE (*node) = 1; + { + if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) + { + warning (OPT_Wattributes, "%qE attribute ignored due to conflict " + "with % attribute", name); + *no_add_attrs = true; + } + else + DECL_UNINLINABLE (*node) = 1; + } else { warning (OPT_Wattributes, "%qE attribute ignored", name); @@ -6704,9 +6713,16 @@ handle_always_inline_attribute (tree *node, tree name, { if (TREE_CODE (*node) == FUNCTION_DECL) { - /* Set the attribute and mark it for disregarding inline - limits. */ - DECL_DISREGARD_INLINE_LIMITS (*node) = 1; + if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node))) + { + warning (OPT_Wattributes, "%qE attribute ignored due to conflict " + "with % attribute", name); + *no_add_attrs = true; + } + else + /* Set the attribute and mark it for disregarding inline + limits. */ + DECL_DISREGARD_INLINE_LIMITS (*node) = 1; } else { diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 2c41bf2..f96cc5e 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -2099,18 +2099,36 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, /* Diagnose inline __attribute__ ((noinline)) which is silly. */ if (DECL_DECLARED_INLINE_P (newdecl) && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) - { - warned |= warning (OPT_Wattributes, - "inline declaration of %qD follows " - "declaration with attribute noinline", newdecl); - } + warned |= warning (OPT_Wattributes, + "inline declaration of %qD follows " + "declaration with attribute noinline", newdecl); else if (DECL_DECLARED_INLINE_P (olddecl) && lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl))) - { - warned |= warning (OPT_Wattributes, - "declaration of %q+D with attribute " - "noinline follows inline declaration ", newdecl); - } + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute " + "noinline follows inline declaration ", newdecl); + else if (lookup_attribute ("noinline", DECL_ATTRIBUTES (newdecl)) + && lookup_attribute ("always_inline", DECL_ATTRIBUTES (olddecl))) + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute " + "noinline follows declaration with attribute " + "always_inline", newdecl); + else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (newdecl)) + && lookup_attribute ("noinline", DECL_ATTRIBUTES (olddecl))) + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute " + "always_inline follows declaration with attribute " + "noinline", newdecl); + else if (lookup_attribute ("cold", DECL_ATTRIBUTES (newdecl)) + && lookup_attribute ("hot", DECL_ATTRIBUTES (olddecl))) + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute cold follows " + "declaration with attribute hot", newdecl); + else if (lookup_attribute ("hot", DECL_ATTRIBUTES (newdecl)) + && lookup_attribute ("cold", DECL_ATTRIBUTES (olddecl))) + warned |= warning (OPT_Wattributes, + "declaration of %q+D with attribute hot follows " + "declaration with attribute cold", newdecl); } else /* PARM_DECL, VAR_DECL */ { diff --git gcc/testsuite/gcc.dg/pr18079-2.c gcc/testsuite/gcc.dg/pr18079-2.c index e69de29..5091dd41b 100644 --- gcc/testsuite/gcc.dg/pr18079-2.c +++ gcc/testsuite/gcc.dg/pr18079-2.c @@ -0,0 +1,16 @@ +/* PR c/18079 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +__attribute__ ((always_inline)) void fndecl1 (void); +__attribute__ ((noinline)) void fndecl1 (void); /* { dg-warning "attribute noinline follows declaration with attribute always_inline" } */ + +__attribute__ ((noinline)) void fndecl2 (void); +__attribute__ ((always_inline)) void fndecl2 (void); /* { dg-warning "attribute always_inline follows declaration with attribute noinline" } */ + + +__attribute__ ((hot)) void fndecl3 (void); +__attribute__ ((cold)) void fndecl3 (void); /* { dg-warning "attribute cold follows declaration with attribute hot" } */ + +__attribute__ ((cold)) void fndecl4 (void); +__attribute__ ((hot)) void fndecl4 (void); /* { dg-warning "attribute hot follows declaration with attribute cold" } */ diff --git gcc/testsuite/gcc.dg/pr18079.c gcc/testsuite/gcc.dg/pr18079.c index e69de29..b84cdeb 100644 --- gcc/testsuite/gcc.dg/pr18079.c +++ gcc/testsuite/gcc.dg/pr18079.c @@ -0,0 +1,33 @@ +/* PR c/18079 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +__attribute__ ((noinline)) +__attribute__ ((always_inline)) +int +fn1 (int r) +{ /* { dg-warning "attribute ignored due to conflict" } */ + return r & 4; +} + +__attribute__ ((noinline, always_inline)) +int +fn2 (int r) +{ /* { dg-warning "attribute ignored due to conflict" } */ + return r & 4; +} + +__attribute__ ((always_inline)) +__attribute__ ((noinline)) +inline int +fn3 (int r) +{ /* { dg-warning "attribute ignored due to conflict" } */ + return r & 8; +} + +__attribute__ ((always_inline, noinline)) +inline int +fn4 (int r) +{ /* { dg-warning "attribute ignored due to conflict" } */ + return r & 8; +}