From patchwork Thu Mar 20 11:07:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 332079 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 828152C0099 for ; Thu, 20 Mar 2014 22:08:33 +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:mime-version:content-type; q=dns; s=default; b=THUP5AdWWo88PRzXvarjcAR6sPXI7ynaYRbSZJpIbXtTw0KtkO fim9zDz5ACStQF+rvVd7qCZvbfVaax5BeLZhJiG3O/rN1lqZ2YwO4Xw+MMBJTKFj qeYBt1dVyrBjR67+Vsi+KJDaT79ZW5U6wYjSWT3kcyg+8kQj7avTD/I2g= 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:mime-version:content-type; s= default; bh=sGUJsYRKDSEh7yPBqXs2lkK5RV0=; b=BSdro9CIQ5r4CHus/9TX +fkmHTH3r8748BvjoA1WcwnHOrUO+sX64RnYt931r1R8xpNhZognGAHo7esp2mtf 4ccRW7+Xb5r0XArLfGdBpcZZc1XL6EAOKs2GHcpwgz+e0ELHdIrnABxxsrKbVRn5 u0hAdIg3nj9rnQmQQS63/MA= Received: (qmail 22160 invoked by alias); 20 Mar 2014 11:08:26 -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 22151 invoked by uid 89); 20 Mar 2014 11:08:25 -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:08:24 +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 s2KB7eO6032313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Mar 2014 07:07:47 -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 s2KB7boA007809 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 20 Mar 2014 07:07:39 -0400 Date: Thu, 20 Mar 2014 12:07:36 +0100 From: Marek Polacek To: GCC Patches Cc: "Joseph S. Myers" Subject: [C PATCH] Warn if inline attributes conflict (PR c/18079) Message-ID: <20140320110736.GL6523@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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? 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..14c838a 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 conflicts with attribute %s", + name, "always_inline"); + *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 conflicts with attribute %s", + name, "noinline"); + *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..adb5cdf 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 conflicts with attribute noinline" } */ + return r & 4; +} + +__attribute__ ((noinline, always_inline)) +int +fn2 (int r) +{ /* { dg-warning "attribute conflicts with attribute noinline" } */ + return r & 4; +} + +__attribute__ ((always_inline)) +__attribute__ ((noinline)) +inline int +fn3 (int r) +{ /* { dg-warning "attribute conflicts with attribute always_inline" } */ + return r & 8; +} + +__attribute__ ((always_inline, noinline)) +inline int +fn4 (int r) +{ /* { dg-warning "attribute conflicts with attribute always_inline" } */ + return r & 8; +}