From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id 194BCC47422 for ; Wed, 17 Jan 2024 07:53:50 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21D8F402B0; Wed, 17 Jan 2024 08:53:49 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 2814D402A6 for ; Wed, 17 Jan 2024 08:53:48 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id A2EED57F0 for ; Wed, 17 Jan 2024 08:53:47 +0100 (CET) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 7D14E59CA; Wed, 17 Jan 2024 08:53:47 +0100 (CET) Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id AA4365857; Wed, 17 Jan 2024 08:53:45 +0100 (CET) Message-ID: <2e1c560d-f19c-4a3c-a066-2e80a9c71f86@lysator.liu.se> Date: Wed, 17 Jan 2024 08:53:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 5/5] eal: replace out of bounds VLA with static_assert To: Stephen Hemminger , dev@dpdk.org Cc: =?UTF-8?Q?Morten_Br=C3=B8rup?= , Tyler Retzlaff References: <20231111172153.57461-1-stephen@networkplumber.org> <20240116184307.162882-1-stephen@networkplumber.org> <20240116184307.162882-6-stephen@networkplumber.org> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <20240116184307.162882-6-stephen@networkplumber.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP 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 On 2024-01-16 19:41, Stephen Hemminger wrote: > Both Gcc, clang and MSVC have better way to do compile time > assertions rather than using out of bounds array access. > The old method would fail if -Wvla is enabled because compiler > can't determine size in that code. Also, the use of new > _Static_assert will catch broken code that is passing non-constant > expression to RTE_BUILD_BUG_ON(). > > Need to add brackets {} around the static_assert() to workaround > a bug in clang. Clang was not handling static_assert() in > a switch case properly. > > Signed-off-by: Stephen Hemminger > Acked-by: Morten Brørup > Acked-by: Tyler Retzlaff > --- > lib/eal/include/rte_common.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h > index c1ba32d00e47..413bed23cb73 100644 > --- a/lib/eal/include/rte_common.h > +++ b/lib/eal/include/rte_common.h > @@ -16,6 +16,7 @@ > extern "C" { > #endif > > +#include > #include > #include > > @@ -495,7 +496,7 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align) > /** > * Triggers an error at compilation time if the condition is true. > */ > -#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) > +#define RTE_BUILD_BUG_ON(condition) { static_assert(!(condition), #condition); } > > /*********** Cache line related macros ********/ > Should one use RTE_BUILD_BUG_ON() or static_assert() in new DPDK code? If static_assert() occasionally needs a work-around, it sounds like keeping using RTE_BUILD_BUG_ON() everywhere is the better choice.