From patchwork Thu Mar 20 11:45:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 332094 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 748052C009A for ; Thu, 20 Mar 2014 22:46:48 +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=QVab5Q2yg/kCvVOSL rc49Hnn7xcU0t22jnXvXEBcfcvKjM56JF/rKy/k84DZiUvNSgvxLwv50J9QXZq5V 67f3COflFGacOVDr4w38YoSvDb7e/cgVoicfYhckdOHhFTY0TK/jsT4jPeno6OI7 NdqumTXQxYqch5WXk/IeBj+UJs= 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=Wbda2/drbH/guJDADRQf/rG LAGM=; b=J64/Od5HUL/Z+kcJvdq7SViBava2b6FumPc0XddsGc12HgcFczaAYBd Mq8tZGDTb7Cwv2WT1cO0Y8GO6ELBl0bxfNe2Zhn2ueJo87nAEh0jAHohAHoqETTt Qx4YZN1fmkJ4Z33gIxtm1Nc3Q/1qTQIoAmriCTVHAF5I9GryMq1k= Received: (qmail 14672 invoked by alias); 20 Mar 2014 11:46:40 -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 14657 invoked by uid 89); 20 Mar 2014 11:46:39 -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 11:46:38 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2KBju2x026939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Mar 2014 07:45:57 -0400 Received: from redhat.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2KBjrhY029126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 20 Mar 2014 07:45:55 -0400 Date: Thu, 20 Mar 2014 12:45:52 +0100 From: Marek Polacek To: Richard Biener Cc: GCC Patches , "Joseph S. Myers" Subject: Re: [C PATCH] Warn if inline attributes conflict (PR c/18079) Message-ID: <20140320114552.GM6523@redhat.com> References: <20140320110736.GL6523@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 12:10:35PM +0100, Richard Biener wrote: > On Thu, Mar 20, 2014 at 12:07 PM, Marek Polacek wrote: > > We should warn if someone wants to use both always_inline and noinline > > attributes. > > > > Regtested/bootstrapped on x86_64-linux. This is hardly 4.9 material, > > so ok for 5.0? > > Shouldn't the warning state that the attribute will be ignored? That is, > the common warning is > > warning (OPT_Wattributes, "%qE attribute ignored", name); > > which could be amended with " due to conflict with ....". Dunno. I did what we do wrt conflicting cold/hot attributes. But here's a patch with what you suggest (with some Extra Quotes). 2014-03-20 Marek Polacek PR c/18079 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. 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/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; +}