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 C5F9D438F4; Thu, 18 Jan 2024 17:54:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0987A42E22; Thu, 18 Jan 2024 17:53:35 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 648DB42E11 for ; Thu, 18 Jan 2024 17:53:31 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1d7164aeac1so3019795ad.1 for ; Thu, 18 Jan 2024 08:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1705596810; x=1706201610; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BL8B6hIPHE2damCHbZr305V3JjoVZuHgS3R5fUMMloQ=; b=zcNPt250AupB9vHCujSXdmdGaCCpF0eqTf4js4eIGEuyVG452CrFOWIw8NWrntImfv nXZ2h6Rmjfx9e4urywcUQcXdFqY58+fQL5jBBNxG32ZQqTaNzQMCWLLiTo2vaVxD8hTx MAy6008efUNCt5C2AutKvucooIEbSIirMj3tJwKvdHdXBd+g+dh+25m9CvCE59BZi08E uKz9+SGCBFu8+EnHtv/F+IRqkJr3qf9hcWByZihw0efpmtKWE0fdkpiZEoFudmDmFiZK PbiXVMuSAZnnNzd90VllMyhLYpC8xJARn2bzg4c5OaAzJqI4fi0qx0P/Lqnq+CK3oZt2 VuWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705596810; x=1706201610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BL8B6hIPHE2damCHbZr305V3JjoVZuHgS3R5fUMMloQ=; b=a5Lhpzl/yRQOmCZsUcYHGhqk7kHXmf8+/PddWQwkinrQNtu2NIAFZBKOxJQhaL0uA7 NBKDaDllmu36b1ogTOT/doyZajdzgR1RYflERKE2m0uOQ223rwaDewn8Xjbxt0RjiLAM CO/tHHEEpbKOko0pOYCe/lTNH8eFx+3110kQBxe9rOtLRfb84uQIG+tW4DUlZnX/zTgP j41sVg0VHytSr+OBzti8qlmtsR/85fy/uEkKbHUycCdDWT9pVvEWqZqtHESp73ep6Zwi b0QdBvfUNpLFXK4w+qIzFmhVhIj3fiGJz2JCcVqb0LIiKNoiZHcXiuSnZqtUhhEO3qIT 2jIQ== X-Gm-Message-State: AOJu0Yw2ztRg2bQtYiEd+rmyANxKKRxvAi0mNTjaWir8dprFc2cJ1CkJ sg3CWbTNWPNfgmoHM4lxhCVk3paEGoBH4Jg9xaSb1YP5rJErwXJb4Te4aMSzTeIH7kJnapcV+wI WGug= X-Google-Smtp-Source: AGHT+IE5THGoY9IejDlsfGJPgztLXJ86WLsIhhLpONID46gebQ8BPmd1iWLHDGyjiT9wsaoXx5aojQ== X-Received: by 2002:a17:902:e5d2:b0:1d7:ae7:850 with SMTP id u18-20020a170902e5d200b001d70ae70850mr932244plf.107.1705596810686; Thu, 18 Jan 2024 08:53:30 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id u2-20020a170903304200b001d706912d1esm1427980pla.225.2024.01.18.08.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 08:53:30 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Tyler Retzlaff Subject: [PATCH v5 6/6] eal: replace out of bounds VLA with static_assert Date: Thu, 18 Jan 2024 08:51:01 -0800 Message-ID: <20240118165315.63959-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118165315.63959-1-stephen@networkplumber.org> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240118165315.63959-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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(). Add workaround for clang static_assert in switch, and missing static_assert in older FreeBSD. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Acked-by: Tyler Retzlaff --- lib/eal/include/rte_common.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 33680e818bfb..aa066125b6cd 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 @@ -492,10 +493,18 @@ rte_is_aligned(const void * const __rte_restrict ptr, const unsigned int align) /*********** Macros for compile type checks ********/ +/* Workaround for toolchain issues with missing C11 macro in FreeBSD */ +#if !defined(static_assert) && !defined(__cplusplus) +#define static_assert _Static_assert +#endif + /** * Triggers an error at compilation time if the condition is true. + * + * The do { } while(0) exists to workaround a bug in clang (#55821) + * where it would not handle _Static_assert in a switch case. */ -#define RTE_BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#define RTE_BUILD_BUG_ON(condition) do { static_assert(!(condition), #condition); } while (0) /*********** Cache line related macros ********/ -- 2.43.0