From patchwork Tue Jan 16 18:41:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135900 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: 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 EDA60438E3; Tue, 16 Jan 2024 19:43:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1424640E13; Tue, 16 Jan 2024 19:43:20 +0100 (CET) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id 38C6540685 for ; Tue, 16 Jan 2024 19:43:16 +0100 (CET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d5f56912daso3734685ad.2 for ; Tue, 16 Jan 2024 10:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1705430595; x=1706035395; 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=bz99mPUMcHch/2QjkxDzWw1aV3kO8SqE6GDE5Wl5hFQ=; b=kwELVWNMsRjyKHYdgtxEJ6c7QSbY6433murMI/V9zd0BHTYudt1eWqLbildJ7Z6QUc EY+EifDcln+LiVyeop0gHOQSdC6a2b0VW5FPg8hAvpZj5ik69RBki1EFUNb2Lpv63TtY hG3fx1Shwy9UMidqSbIF6vzf73MmFsOgxeLx+IN4Wwywjfmx9UdeL3XPVtdY71o2tYaO T6Ft+h+xKPzGJNMnMEoanDw+BzIGHXB4zgZvwJMyShwKiiOlGHhenUr9vSOMg87lz/AE /EDgyS6/DNMpqHWMHPg2zilmy/mC2b3TMEwYyVFHvmZlfVwbO01Z/P7OMY1+DFmkVikG hT9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705430595; x=1706035395; 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=bz99mPUMcHch/2QjkxDzWw1aV3kO8SqE6GDE5Wl5hFQ=; b=UqRTpc6QfbvF1yZNZujtr4n84dV8VnIgqcWk+RO+VnetsR4Rmi9xSgJTL69SCfhw8n t+N9qzptynsoxFdHuyYM9l0x1thqnm1o5WtJdxQqNFDPMH3Lto1oeEVKXxZpuRvFZtGH vXM1E14S64zSIiVi8YJDmNkTNqvUSOgAYtkIOV3HCcN1EZ65PtvxzEELeGCUis5c7bFE arPGYtwzcOf1RGv+BqUVlQhhRlFxFOdRRHP5u3yHY5zuTp8ce4yNB32umOgZhTPdf7HL o96tfhYBWXttlD1wAEwoqIyQnaVi1KsUp1yz0cGkcFPOiOgOg9kpinBYViAnquaTSsqL ShaQ== X-Gm-Message-State: AOJu0YxKOlhVNdEQ76BmVdlqX8okLqFpiocOWqdHXPz1iKzZ/NzG4tGi glf726Yxj6EORhsGSIivJTUEA1E4nZV7rhN732ePaEd4oRAf8w== X-Google-Smtp-Source: AGHT+IEwZ3x+S08G9b3N7qJ1oP6jSqHp7cv8OtBbRwgwPr8pGC8rCE6lDLjwcGb/iBBr/2P2OfjJSg== X-Received: by 2002:a17:902:dacc:b0:1d4:4768:5f with SMTP id q12-20020a170902dacc00b001d44768005fmr9257692plx.37.1705430595530; Tue, 16 Jan 2024 10:43:15 -0800 (PST) Received: from hermes.lan (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id m8-20020a1709026bc800b001d60a70809bsm379238plt.168.2024.01.16.10.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 10:43:15 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Morten_Br?= =?utf-8?q?=C3=B8rup?= , Tyler Retzlaff Subject: [PATCH v3 5/5] eal: replace out of bounds VLA with static_assert Date: Tue, 16 Jan 2024 10:41:15 -0800 Message-ID: <20240116184307.162882-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240116184307.162882-1-stephen@networkplumber.org> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240116184307.162882-1-stephen@networkplumber.org> MIME-Version: 1.0 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(). 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 Acked-by: Andrew Rybchenko --- 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 ********/