From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9320CA00BE; Mon, 11 Apr 2022 17:18:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8594241611; Mon, 11 Apr 2022 17:18:37 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2075.outbound.protection.outlook.com [40.107.22.75]) by mails.dpdk.org (Postfix) with ESMTP id 6046B415D7 for ; Mon, 11 Apr 2022 17:18:36 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jmT00qdc0yN0q3CjT3KPRNzKCCB3GNqIiQ7fu/x/LjtIYojf8931aR95kzhI6JyDqiQQeK+3zRmnBmlL+8sY0LKBu3TxpMBex8PxM9jmkdRNCfPyfcso4UfuuDKUYvExepLwa4cVLv5S7IfTJ+BRb/YVzN1d7AFUErq3bKAshSRH1VjcaBdL6EghQproeVoEWvSkA+mF9aY/jbSdSY4tWtpTv7aHOBwPiSD9h1Sx+9ciapYVstPZ0NCK/qfuJ/DHPfg4LyK+WqDOFKoUtxOdgtwxgiKl0fZ5uRfRnytJgQl00G63zF0kQMM/65VF+0FM5BvHCS92kIkuipNPnOWkFw== 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=9t/hTjCAT0r0pT1YrTQwOHpzMcHrkNUGsWIL3KI0gJk=; b=h76aRImFIc6nDUoHzQGI5uQ4cQ1hhCu/05XmdhV2ZTCPAfNEjSA881jbU16roaWkoL3wVDY/zXnvwmB+YKLFsijSBPN2AQ4TdSERGNwIdWiLlEaei+/i80caXiglVrThgWbGuNXzUpVQvOChAL4unS51T/qFaLxJ3VWiZYhdRQhL/bVfU6kzVAEL46sSZQdHuEy5PhHAP55gT1irnZQlOVWhmGbSS4J2oWkeZcGIg7Zypu5FZsx0CTG2MMSPJ0Kqawd7jvIJYRbKBlooaPzkuAuD52JS1uMehRdWYxVDusdt4eGbIpfMq/1Vco+veZqUQcDr4vNyS5oRRUg70Pf7aQ== 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=9t/hTjCAT0r0pT1YrTQwOHpzMcHrkNUGsWIL3KI0gJk=; b=ky1wpchbEwHAatu6YNBFc7fuJYh4UU+U57yaFxRxewmBdu3mFPgZicZHY9KfGskGzi23NojBOPR0vZ/wH73bcPkaCrGUh+9xoRybY71K5qEFe/J7eP8oHzF1rR8DRW9604G9DNfLyKdlPWUY4QY/cApFxHN++0p9shjVOuRFU+Y= Received: from AM6P195CA0042.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:87::19) by HE1PR0702MB3657.eurprd07.prod.outlook.com (2603:10a6:7:7e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.17; Mon, 11 Apr 2022 15:18:35 +0000 Received: from VE1EUR02FT048.eop-EUR02.prod.protection.outlook.com (2603:10a6:209:87:cafe::50) by AM6P195CA0042.outlook.office365.com (2603:10a6:209:87::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29 via Frontend Transport; Mon, 11 Apr 2022 15:18:34 +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 VE1EUR02FT048.mail.protection.outlook.com (10.152.13.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.5144.20 via Frontend Transport; Mon, 11 Apr 2022 15:18:34 +0000 Received: from ESESSMB501.ericsson.se (153.88.183.162) by ESESSMR505.ericsson.se (153.88.183.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.27; Mon, 11 Apr 2022 17:17:37 +0200 Received: from seliiuapp00218.seli.gic.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.189) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Mon, 11 Apr 2022 17:17:37 +0200 Received: from localhost.localdomain (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliiuapp00218.seli.gic.ericsson.se (Postfix) with ESMTP id 4ED9160160; Mon, 11 Apr 2022 17:17:37 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: Bruce Richardson , Thomas Monjalon , David Marchand , , , , Stephen Hemminger , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH 1/3] eal: add macro to warn for unused function return values Date: Mon, 11 Apr 2022 17:15:57 +0200 Message-ID: <20220411151559.164217-1-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: 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: 79926fc1-27c6-4ff1-2d44-08da1bce8b87 X-MS-TrafficTypeDiagnostic: HE1PR0702MB3657:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WzLrW3zhPIiL3Uyqr92+MrykT8UOZnGqZJzyygcDdiVRqr5V8qZtKfON3rYBpjYuL33seMhy++2ddndhgunwujMGtBA6HN4n1i+0KGwcr4srmr/9N4GEkeuJmFY/2K3Secv0Yxg1lIOo+OS96LGNp2su7iq0HB45UGfilrabbU7BY74+n1EAjZIzpPmUSMXDYUHM0HJVd+3DBF/52xCsinbVT8l8560u1avMVLugAN6Zu6ZshygCgtT3xfhzVuDuHsz+T/cZrFrsDza+kVUrTRHLKXI6HliqDRePlfSTqsKCcdXXIZ8NF05+RthYrhlKTAUvbNPHPCnrnrBYadDO8oobeXq5wo52UQJLBbvyH048rxYQWp/gtjhyUUcFNDKCHau2Gl014To7ebL2lRAK25NAu34t3qJ/0hxBfVepXklLCNTdlkQj15zJzMIQ312mRbtYQPuFvhtazCR0tDgDz+0vwWlGH9QUQehL/0fBud4FWsSYyv2r8jgZGvtFJLSQDy8iU9BcR3tuP0fYbOsiZ7sIIXUDnKzqxJbgVas5b5MVOHdhL1xkehbDMjirkTaMvAK96jxGgIu+tdKZ2zZYXVp/whqsnqj8TVhCE1pR9ckVXDXpF9ekBb7cZelz0JwjjETgEHG+91TALtp6uaZTNzwDVKUK1aN1DY6PWcYrfe8ERsirJavWVZSzDaeMNiEL 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)(46966006)(40470700004)(36840700001)(6666004)(316002)(47076005)(54906003)(6916009)(2906002)(36860700001)(186003)(107886003)(26005)(2616005)(6266002)(1076003)(66574015)(5660300002)(336012)(83380400001)(508600001)(40460700003)(8936002)(86362001)(4326008)(82310400005)(7636003)(82960400001)(356005)(8676002)(70206006)(36756003)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 15:18:34.3670 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79926fc1-27c6-4ff1-2d44-08da1bce8b87 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: VE1EUR02FT048.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0702MB3657 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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. Changes since RFC: * Include usage recommendation and GCC peculiarities in the macro documentation. Acked-by: Bruce Richardson Signed-off-by: Mattias Rönnblom --- lib/eal/include/rte_common.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 4a399cc7c8..67587025ab 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -222,6 +222,31 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) */ #define __rte_noreturn __attribute__((noreturn)) +/** + * Issue a warning in case the function's return value is ignored. + * + * The use of this attribute should be restricted to cases where + * ignoring the marked function's return value is almost always a + * bug. With GCC, some effort is required to make clear that ignoring + * the return value is intentional. The usual void-casting method to + * mark something unused as used does not suppress the warning with + * this compiler. + * + * @code{.c} + * __rte_warn_unused_result int foo(); + * + * void ignore_foo_result(void) { + * foo(); // generates a warning with all compilers + * + * (void)foo(); // still generates the warning with GCC (but not clang) + * + * int unused __rte_unused; + * unused = foo(); // does the trick with all compilers + * } + * @endcode + */ +#define __rte_warn_unused_result __attribute__((warn_unused_result)) + /** * Force a function to be inlined */ -- 2.25.1