Message ID | 20220410135140.161842-1-mattias.ronnblom@ericsson.com (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | David Marchand |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A8564A00BE; Sun, 10 Apr 2022 15:52:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B33340685; Sun, 10 Apr 2022 15:52:51 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2084.outbound.protection.outlook.com [40.107.22.84]) by mails.dpdk.org (Postfix) with ESMTP id 786A540042 for <dev@dpdk.org>; Sun, 10 Apr 2022 15:52:49 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GV5g80xx1X0pCji+dhcs6LKRIMB7if7zFtQHDrMoBIRy1H2gaed79DR54jFms0ogbsYDiEnfzcUBy8euOC+XQ8HbiWN1WddlfDm7S1V1i+3LDmRxtXtLuGDOBl/WYUd4IaQJ4GpJ5FWIn78/3SEdiHKSsG+uEreKz4dCsRihy6oxfn/c91CP0PM+DzNwQmNy/LlmVWmN31gX1ORhX26rRJl63C+dm28LwUaYgsXYV1nnoKLWIqRFqJqmUgAq4B2AwFoFvNZyApQn6ei5OGBVAOa42DJha/hz7nf5eYBpat+TyqXo3A0dhcOnSUiqv8rRTBN4e+rCsGnW2WHsGsws2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sDAD7K0btR9DkGH+ZGLgNC8vzjsCRJN2/dL38FbKxAc=; b=Ohb0sIkvSY+HsbIeaCy3FTNYsaotblymLVGEFfnIs3tiJOkEjGFflbYGgWEKqLspDLoIe56B4yT/V6qdhd6hI7kNvgRduWieuUkoHFrLxMxZ2xFwmdyKz2YJ6CI3HwuoNDMM70HjcSQrzgho2vfOodu4hiSM/nRDcoUWEJ9/iZRE6bkvjYktqlZR7RMA1at5JStcJEICI2XTPqBviwSrBqX0EP0Lp40c0t+Uu5XoXHCiWSL7/ox7oBDJuyYeLTFw+CykTS5wT1Tc9S57QQNEIb9cYZSmwYp0aJagSKhm9HN3oWU6z2gcNJKVtGbXP+TJlkR8Y57L2ggsQHVkA4bFlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=arm.com smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDAD7K0btR9DkGH+ZGLgNC8vzjsCRJN2/dL38FbKxAc=; b=ulYS/ymZVvF8XSrl1NUPtvDk5Or3TPdN3r+sGb/YLQbDWAAcwaZ9nKmJ+TXg2H/3zVFIgMffojUmh1DWuOPc94U/LDai5j6QxLpPdeZzrgN5GFuhs6FrEnarWIDIoViOwbI2gGdKIBjDMPFLYuyUcTKrlMTT4+IOl1YQe3Aa8NE= Received: from AM5PR0601CA0046.eurprd06.prod.outlook.com (2603:10a6:203:68::32) by AM4PR0701MB2116.eurprd07.prod.outlook.com (2603:10a6:200:4a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.16; Sun, 10 Apr 2022 13:52:47 +0000 Received: from AM5EUR02FT072.eop-EUR02.prod.protection.outlook.com (2603:10a6:203:68:cafe::18) by AM5PR0601CA0046.outlook.office365.com (2603:10a6:203:68::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29 via Frontend Transport; Sun, 10 Apr 2022 13:52:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; Received: from oa.msg.ericsson.com (192.176.1.74) by AM5EUR02FT072.mail.protection.outlook.com (10.152.9.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.5144.20 via Frontend Transport; Sun, 10 Apr 2022 13:52:46 +0000 Received: from ESESSMB504.ericsson.se (153.88.183.165) by ESESBMR501.ericsson.se (153.88.183.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.27; Sun, 10 Apr 2022 15:52:46 +0200 Received: from seliiuapp00218.seli.gic.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.192) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Sun, 10 Apr 2022 15:52:46 +0200 Received: from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliiuapp00218.seli.gic.ericsson.se (Postfix) with ESMTP id 6D794601CB; Sun, 10 Apr 2022 15:52:46 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com> To: <dev@dpdk.org> CC: Thomas Monjalon <thomas@monjalon.net>, David Marchand <david.marchand@redhat.com>, <Honnappa.Nagarahalli@arm.com>, <mb@smartsharesystems.com>, <hofors@lysator.liu.se>, =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= <mattias.ronnblom@ericsson.com> Subject: [RFC 1/3] eal: add macro to warn for unused function return values Date: Sun, 10 Apr 2022 15:51:38 +0200 Message-ID: <20220410135140.161842-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <DBAPR08MB581495F6710F9CD5BAA40D3798E39@DBAPR08MB5814.eurprd08.prod.outlook.com> References: <DBAPR08MB581495F6710F9CD5BAA40D3798E39@DBAPR08MB5814.eurprd08.prod.outlook.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 62013b02-9a85-40f3-6f46-08da1af96505 X-MS-TrafficTypeDiagnostic: AM4PR0701MB2116:EE_ X-Microsoft-Antispam-PRVS: <AM4PR0701MB21169784AC9341DC4D377ABCE1EB9@AM4PR0701MB2116.eurprd07.prod.outlook.com> X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BogITDHYEBWx4OVT/dJcUMMNafjt8KAd2HFWdyGq9u1KaWFN5ubVAaDe3Diq7F1NkglvtwRmRUkxWlC7UXQ6SzBWqKZtb++VIMWfilyF3WvqTIvyeZW9lKGzP8Dhmt6NazAQQEb6cGamphjsSaeU7rHiCQ6xEGAbtw2pmdTXFSWhvLfiYpD9M4Pw0I3z2Nukw+iAeEzWXnZX+rxT8tQV6x49164xcta14Cw7RN/nk50hGOzH0di0IiGumVLOT0M5gmcMY7eX9iTu0mQyy7WLcfi6cxL/54u8/BUHkWCgGLruufHtqeziizEBFLb/K7+fOH2M5sy6/h1Vf9tysVSi4YkvCPmBCvrM/TJk9fg7gwE57E0s1NOgpFu9I2tamn6qtTX2UI71Ph/5GVXQsTptPHSqFOgdv+GY7iws7+XFcb5q+rvm9rvasruuiO+j/kXe280Fv1Cv6LVZyRu6c8WBdhAbPCMqnJ6gtKaSN8LIwby3vPDRWLXNQYjHVAbISdoloEAijrI6U6hmB5KKNnQSnk6RpO9364Zkzub+JzYUfFh8lqyFP7A3vsoqULn3z2LG0SkuqJynsOiiYQLNG4hiQ2ErVGGfPA8sgYlH0wkuPFRkk0WFi8KkLbsHz3wdwtoT1vG2XVTMMM8vKXklnQG7hKj6sb9X8RBZvKf9/ZdpclIbVxQAd83+9s/tnPzHj2UrhB4G96VVOypBIxFbD/FKGA== X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(1076003)(107886003)(2616005)(34020700004)(70586007)(70206006)(83380400001)(8676002)(4326008)(336012)(26005)(186003)(6266002)(66574015)(86362001)(47076005)(508600001)(5660300002)(36756003)(54906003)(8936002)(82960400001)(4744005)(356005)(82310400005)(7636003)(316002)(36860700001)(40460700003)(6916009)(6666004)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2022 13:52:46.9599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62013b02-9a85-40f3-6f46-08da1af96505 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR02FT072.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0701MB2116 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions <dev.dpdk.org> List-Unsubscribe: <https://mails.dpdk.org/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://mails.dpdk.org/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <https://mails.dpdk.org/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org |
Series |
[RFC,1/3] eal: add macro to warn for unused function return values
|
|
Checks
Context | Check | Description |
---|---|---|
ci/checkpatch | warning | coding style issues |
Commit Message
Mattias Rönnblom
April 10, 2022, 1:51 p.m. UTC
This patch adds a wrapper macro __rte_warn_unused_result for the
warn_unused_result function attribute.
Marking a function __rte_warn_unused_result will make the compiler
emit a warning in case the caller does not use the function's return
value.
Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
lib/eal/include/rte_common.h | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Sun, 10 Apr 2022 15:51:38 +0200 Mattias Rönnblom <mattias.ronnblom@ericsson.com> wrote: > This patch adds a wrapper macro __rte_warn_unused_result for the > warn_unused_result function attribute. > > Marking a function __rte_warn_unused_result will make the compiler > emit a warning in case the caller does not use the function's return > value. > > Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> Looks good, but are these attributes compiler specific?
On 2022-04-10 20:02, Stephen Hemminger wrote: > On Sun, 10 Apr 2022 15:51:38 +0200 > Mattias Rönnblom <mattias.ronnblom@ericsson.com> wrote: > >> This patch adds a wrapper macro __rte_warn_unused_result for the >> warn_unused_result function attribute. >> >> Marking a function __rte_warn_unused_result will make the compiler >> emit a warning in case the caller does not use the function's return >> value. >> >> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> > > Looks good, but are these attributes compiler specific? GCC and LLVM clang supports this and many other attributes (some of which are already wrapped by ___rte_* macros). The whole attribute machinery is compiler (or rather, "implementation") specific, as suggested by the double-underscore prefix (__attribute__). I don't know about icc.
> From: Mattias Rönnblom [mailto:mattias.ronnblom@ericsson.com] > Sent: Sunday, 10 April 2022 15.52 > > This patch adds a wrapper macro __rte_warn_unused_result for the > warn_unused_result function attribute. > > Marking a function __rte_warn_unused_result will make the compiler > emit a warning in case the caller does not use the function's return > value. > > Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> > --- > lib/eal/include/rte_common.h | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/lib/eal/include/rte_common.h > b/lib/eal/include/rte_common.h > index 4a399cc7c8..544e7de2e7 100644 > --- a/lib/eal/include/rte_common.h > +++ b/lib/eal/include/rte_common.h > @@ -222,6 +222,11 @@ static void > __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) > */ > #define __rte_noreturn __attribute__((noreturn)) > > +/** > + * Issue warning in case the function's return value is ignore Typo: ignore -> ignored Consider: warning -> a warning > + */ > +#define __rte_warn_unused_result __attribute__((warn_unused_result)) > + > /** > * Force a function to be inlined > */ > -- > 2.25.1 > Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
On Sun, Apr 10, 2022 at 03:51:38PM +0200, Mattias Rönnblom wrote: > This patch adds a wrapper macro __rte_warn_unused_result for the > warn_unused_result function attribute. > > Marking a function __rte_warn_unused_result will make the compiler > emit a warning in case the caller does not use the function's return > value. > > Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> > --- This is good to have, thanks. Series-acked-by: Bruce Richardson <bruce.richardson@intel.com>
On 2022-04-11 11:16, Bruce Richardson wrote: > On Sun, Apr 10, 2022 at 03:51:38PM +0200, Mattias Rönnblom wrote: >> This patch adds a wrapper macro __rte_warn_unused_result for the >> warn_unused_result function attribute. >> >> Marking a function __rte_warn_unused_result will make the compiler >> emit a warning in case the caller does not use the function's return >> value. >> >> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> >> --- > > This is good to have, thanks. > > Series-acked-by: Bruce Richardson <bruce.richardson@intel.com> There is one issue with this attribute in combination with GCC: a warn_unused_result warning cannot easily be suppressed in the source code of the caller. The usual cast-to-void trick doesn't work with this compiler (but does work with clang). This behavior limit the usefulness of this attribute to function where it's pretty much always a bug if you ignore the return value. I will update the macro doc string with some details around this.
On 2022-04-11 09:17, Morten Brørup wrote: >> From: Mattias Rönnblom [mailto:mattias.ronnblom@ericsson.com] >> Sent: Sunday, 10 April 2022 15.52 >> >> This patch adds a wrapper macro __rte_warn_unused_result for the >> warn_unused_result function attribute. >> >> Marking a function __rte_warn_unused_result will make the compiler >> emit a warning in case the caller does not use the function's return >> value. >> >> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> >> --- >> lib/eal/include/rte_common.h | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/lib/eal/include/rte_common.h >> b/lib/eal/include/rte_common.h >> index 4a399cc7c8..544e7de2e7 100644 >> --- a/lib/eal/include/rte_common.h >> +++ b/lib/eal/include/rte_common.h >> @@ -222,6 +222,11 @@ static void >> __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) >> */ >> #define __rte_noreturn __attribute__((noreturn)) >> >> +/** >> + * Issue warning in case the function's return value is ignore > > Typo: ignore -> ignored > > Consider: warning -> a warning > OK. >> + */ >> +#define __rte_warn_unused_result __attribute__((warn_unused_result)) >> + >> /** >> * Force a function to be inlined >> */ >> -- >> 2.25.1 >> > > Reviewed-by: Morten Brørup <mb@smartsharesystems.com> > Thanks!
On Mon, Apr 11, 2022 at 10:16:35AM +0100, Bruce Richardson wrote: > On Sun, Apr 10, 2022 at 03:51:38PM +0200, Mattias Rönnblom wrote: > > This patch adds a wrapper macro __rte_warn_unused_result for the > > warn_unused_result function attribute. > > > > Marking a function __rte_warn_unused_result will make the compiler > > emit a warning in case the caller does not use the function's return > > value. > > > > Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com> > > --- > > This is good to have, thanks. > > Series-acked-by: Bruce Richardson <bruce.richardson@intel.com> +1 Series-acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 4a399cc7c8..544e7de2e7 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -222,6 +222,11 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) */ #define __rte_noreturn __attribute__((noreturn)) +/** + * Issue warning in case the function's return value is ignore + */ +#define __rte_warn_unused_result __attribute__((warn_unused_result)) + /** * Force a function to be inlined */