From 5a3f9f4cc3c31b0f521932df80a9ac541edec073 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 29 Oct 2019 18:25:04 +0530 Subject: [PATCH] LU-12923 utils: Use BUILD_BUG_ON() for wirehdr.c & wirecheck.c This patch replaces all CLASSERT() with user defined BUILD_BUG_ON() for file lustre/utils/wirehdr.c and lustre/utils/wirecheck.c Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: If46603158a9ad311762fe51839000c39a0b15307 Reviewed-on: https://review.whamcloud.com/36711 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Petros Koutoupis Reviewed-by: Oleg Drokin --- lustre/utils/wirecheck.c | 6 +++--- lustre/utils/wirehdr.c | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lustre/utils/wirecheck.c b/lustre/utils/wirecheck.c index e252ecd..f6c9bad 100644 --- a/lustre/utils/wirecheck.c +++ b/lustre/utils/wirecheck.c @@ -56,13 +56,13 @@ do { \ #define STRINGIFY(a) #a #define CHECK_CDEFINE(a) \ - printf(" CLASSERT("#a" == "STRINGIFY(a) ");\n") + printf(" BUILD_BUG_ON("#a" != "STRINGIFY(a) ");\n") #define CHECK_CVALUE(a) \ - printf(" CLASSERT("#a" == %lld);\n", (long long)a) + printf(" BUILD_BUG_ON("#a" != %lld);\n", (long long)a) #define CHECK_CVALUE_X(a) \ - printf(" CLASSERT("#a" == 0x%.8x);\n", a) + printf(" BUILD_BUG_ON("#a" != 0x%.8x);\n", a) #define CHECK_DEFINE(a) \ do { \ diff --git a/lustre/utils/wirehdr.c b/lustre/utils/wirehdr.c index cb0aa1b..f9f33d9 100644 --- a/lustre/utils/wirehdr.c +++ b/lustre/utils/wirehdr.c @@ -52,12 +52,10 @@ #define LASSERT(cond) if (!(cond)) { printf("failed " #cond "\n"); ret = 1; } #define LASSERTF(cond, fmt, ...) if (!(cond)) { printf("failed '" #cond "'" fmt, ## __VA_ARGS__);ret = 1;} /* - * Compile-time LASSERT, which verifies correctness at compile-time rather - * than runtime. If "cond" is true, then there are two different cases - * ("(non-zero)" and "0"). If "cond" is false, then there are two identical - * cases ("0" and "0"), which is an error that causes the compiler to complain. + * BUILD_BUG_ON() is Compile-time check which verifies correctness at + * compile-time rather than runtime. */ -#define CLASSERT(cond) do {switch (1) {case (cond): case 0: break; } } while (0) +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) int ret; @@ -65,10 +63,10 @@ void lustre_assert_wire_constants(void); int main() { - lustre_assert_wire_constants(); + lustre_assert_wire_constants(); - if (ret == 0) - printf("wire constants OK\n"); + if (ret == 0) + printf("wire constants OK\n"); - return ret; + return ret; } -- 1.8.3.1