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 12D76438E4; Wed, 17 Jan 2024 19:26:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9B0AE410F2; Wed, 17 Jan 2024 19:26:01 +0100 (CET) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by mails.dpdk.org (Postfix) with ESMTP id EEF0140ED6 for ; Wed, 17 Jan 2024 19:25:56 +0100 (CET) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-28beb1d946fso9473224a91.0 for ; Wed, 17 Jan 2024 10:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1705515956; x=1706120756; 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=bOrbVpKEVbKkOmwo3x2yeTW4pbaRRg4gumE9fvaTD5Y=; b=hlzDTNAYStYelqGnecTwGccQORb4KNHuja06RK4imr2E80ChnkUpFuegj1ngqwuFCX qAP25O7G10clFSiRk047vk5Ov1Qcs6yecAZioFftWvPo0ocSdGtN5Qtadcey7CNrgZYk 6+sUL9+Vz6JatZmldSEsIKyfVJO36yavg5NpHF03cO8HsAghrlyN7KZyar3UTC+xNA3d 4hfJ36OqcTpk2up7doA7AXx3WyLo4bSG0y+jBSZ7keQ1tUyUr37vd4NrRZ9sWGGSNYlT 8dKV8L5dNhrvAuJF0bv4vWsmTUbGQjsdXf+HQcgVtyIQA25z4Kv6wWPGFX0LVuvWttxd U+Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705515956; x=1706120756; 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=bOrbVpKEVbKkOmwo3x2yeTW4pbaRRg4gumE9fvaTD5Y=; b=bJs78/HovRazhHNKFNwsHf+AoKlhoq67REOoE2+Evey78Cr4mBkSzrSJXKHvrObBQL JxhLaeMy135cG3+9IbJRxPeoDJY7t+3kT7+853E1L70zbE1R8O1CDtZtP5pSr3Qy9nV7 drnN6gETDI4zgRXA03a6z2bcnoqFNTB3cXo5fujqoCtNavt/ZRrypv8EildkdrgSkshi EW2o7lbDJ8rP6YECMBQjia+4WwxPCifE927kRZ8Ml50nAjKuhrxCcI0672beuiB/bJLp EVDUd4bHsUSLo/9aoJSlQTcsNLsaI+4Q4j2V0nCPGFSgoKnG2k+S0/yiIx1QVB1dfrb8 jheA== X-Gm-Message-State: AOJu0YzIQy1mrZ0+0rjFPJsCLP4mEGEpO4qq9V8hx40aaTpTtHf3Vtz6 LCtIAyLAFY7TCeMyqYWnAb0LSgZLBiGr1ojVUJOX4QUOcT4X4Q== X-Google-Smtp-Source: AGHT+IEriSuYz4Z9bYU/UJsLnd/rN2JcvdjZvVA4ZstxOuzmb2smRaWk0C2XOlKK+KC2kFaZQUM10Q== X-Received: by 2002:a17:90b:8d5:b0:28e:7528:3d4c with SMTP id ds21-20020a17090b08d500b0028e75283d4cmr2497386pjb.55.1705515956188; Wed, 17 Jan 2024 10:25:56 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id qj15-20020a17090b28cf00b0028ce507cd7dsm14334124pjb.55.2024.01.17.10.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 10:25:55 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Tyler Retzlaff , Andrew Rybchenko Subject: [PATCH v4 6/6] eal: replace out of bounds VLA with static_assert Date: Wed, 17 Jan 2024 10:20:00 -0800 Message-ID: <20240117182541.211125-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240117182541.211125-1-stephen@networkplumber.org> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240117182541.211125-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(). 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 33680e818bfb..f63119b444fa 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 ********/ -- 2.43.0