Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3885798imw; Mon, 18 Jul 2022 16:45:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbCo9SxK8Sr5hP4N2EISZ1i1H4WEwIrsnnWxUs+KdWhE5proaaxCERI+tdDESoFmVS4uku X-Received: by 2002:a17:906:53c7:b0:711:d2e9:99d4 with SMTP id p7-20020a17090653c700b00711d2e999d4mr27717490ejo.716.1658187909897; Mon, 18 Jul 2022 16:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658187909; cv=none; d=google.com; s=arc-20160816; b=dG2Ni+JxJ9gCAGJ+KQ1rqBpE6/TxhsEhvdLU07OSbMfWRtCqRs/EHhx6mVBThFnDrs E+gYisuPu4/rN1eQjxF4pQuAL7jwfrvVZBLvzYtb6BNrli+mRcM18XBUQrzHw7pjtuNx 45GXPsXZC6PV5wiKfs+tGTgRtygXsjJdOMnXy/dgqTfBf09Rrs6+mqiZBhzO6PCi0xVg HitBgtHxknOLhKwhkTZRe35C3eSc+VWxio+xHr3soUmH9jN01AiNRUw6NFobZ8tJ7SPS GcJ3vYMNPBskLhcZ5//+BgwEbrS2l6ApHwvOe9Ke/Cfi+inN/8GdNMK64KOZV178A88I FR6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :references:mime-version:message-id:in-reply-to:date:dkim-signature; bh=kr+g0QLyfEsKisyWseSQidWHG7rTs+Z9BjnCTx3ihTc=; b=qNzKe4JAVIYT0oZjNSh1yoYx9mqyhTIs5S+ZYczFtiC0VlZ/S242yT7rguIwMzmyoK v/sr+fT5orzy5HPJTKZeS69BXUx+M2mES3nBvJVXp13XE960uKc7/z4zDoaaWKvPV+hS 14Kqm0AdoXbtSshbvj5Rm73SPyEtCa/OACrHnuVeOSbnZZkleCfXFrfDKHPVeVxNS3jW oSzLEkA+h0Gcof7uiN82uQHNuz96T4/FuckN6hM+8d32qk1EISnNo7HwsV+1WMWlwZxK A6vJ8qPjRHGigwhI+yFs9UBsYRg1tNJq2KAKrcpueAZE73FAinreViUXl7tMGbby6oVE frqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UALDjrOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s25-20020a1709064d9900b00722e779f365si14270606eju.376.2022.07.18.16.44.45; Mon, 18 Jul 2022 16:45:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UALDjrOG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiGRXGh (ORCPT + 99 others); Mon, 18 Jul 2022 19:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiGRXGg (ORCPT ); Mon, 18 Jul 2022 19:06:36 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC20F275EC for ; Mon, 18 Jul 2022 16:06:35 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id r142-20020a632b94000000b0041a18177a5dso1630192pgr.10 for ; Mon, 18 Jul 2022 16:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=kr+g0QLyfEsKisyWseSQidWHG7rTs+Z9BjnCTx3ihTc=; b=UALDjrOGFK63RNNlZA9jDLc+QBDSAH1EdrvRdsbNPiAxlbTp5/vXOzhCE0JdyzjItg 6Guq1N/aGwWPV+Lqa8Faop3fIKcrvQylt/GMLCPQ/7GSHA3Tai77w4t5p8omE3dh63a5 ZvP0h4vC2B2xEwEhysFiZd9ED6dCdIoGNVpxRoS1WZABUjlOKu8WUPczczpe+tVS9M9d 9zBPC7I6ns7Gu48exyHoPaD1dh3sfob4A9ZMTpZE68k0cJwNgu19cJXyd/sqjPn89v5W jR7kBLNsJg8SR0yswTuj0tmeMqIjb3s9rkr8/+e/IITIMXsDBURqpQP2W0buSK4lgJgt MgCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=kr+g0QLyfEsKisyWseSQidWHG7rTs+Z9BjnCTx3ihTc=; b=S6hiNQ822xG5apmLnR/1kxI0cE0DIKZqUrn3nlM6PSTR5WYqMWLrqzvOTeW6dAdMgd MQ/nCn59Ni9w+RgdjF6DvO+zQrh4UnukKt1v2X3T30l/fkW9whzk5nYbB17tqF1ITnzr Wb81kR/CVvRF0p/DxrJklQZB3U8rRC0PX6jCOgqbEh+yvdP0CHS/tISJonNn+wzB0TYR BGfvRNY1VMFS+3l1uf731RD4XBYXYlnbo3hD/DdqzCpnPD1//gQNvT3sbno/hxLcKrZq 0UNmVesw+HUgMRQCOvscnAXWFY0H/PHJCpyZo0frtlciHsfavAcEoel4D7z9M2Xlfsn4 Q3aA== X-Gm-Message-State: AJIora8VMxI5uh361C4m//wODNUiPBKT25HH4eM9IjNGvsLTFvxCDLw8 rRGiy0EYlOzIfeQGqAvXD5MsV+iLx3sC/PW6Lg== X-Received: from justinstitt.mtv.corp.google.com ([2620:15c:211:202:f922:7e91:d8e8:24c4]) (user=justinstitt job=sendgmr) by 2002:a17:903:3093:b0:16b:deea:4d36 with SMTP id u19-20020a170903309300b0016bdeea4d36mr30327719plc.126.1658185595359; Mon, 18 Jul 2022 16:06:35 -0700 (PDT) Date: Mon, 18 Jul 2022 16:06:26 -0700 In-Reply-To: Message-Id: <20220718230626.1029318-1-justinstitt@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v4] lib/test_printf.c: fix clang -Wformat warnings From: Justin Stitt To: ndesaulniers@google.com Cc: andriy.shevchenko@linux.intel.com, justinstitt@google.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, nathan@kernel.org, pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org, trix@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org see warnings: | lib/test_printf.c:157:52: error: format specifies type 'unsigned char' | but the argument has type 'int' [-Werror,-Wformat] test("0|1|1|128|255", | "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1); - | lib/test_printf.c:158:55: error: format specifies type 'char' but the | argument has type 'int' [-Werror,-Wformat] test("0|1|1|-128|-1", | "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1); - | lib/test_printf.c:159:41: error: format specifies type 'unsigned short' | but the argument has type 'int' [-Werror,-Wformat] | test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627); There's an ongoing movement to eventually enable the -Wformat flag for clang. Previous patches have targeted incorrect usage of format specifiers. In this case, however, the "incorrect" format specifiers are intrinsically part of the test cases. Hence, fixing them would be misaligned with their intended purpose. My proposed fix is to simply disable the warnings so that one day a clean build of the kernel with clang (and -Wformat enabled) would be possible. It would also keep us in the green for alot of the CI bots. Link: https://github.com/ClangBuiltLinux/linux/issues/378 Suggested-by: Nathan Chancellor Suggested-by: Nick Desaulniers Signed-off-by: Justin Stitt --- changes from v1 -> v2: * moved NOWARN macro definition to a more appropriate location * using __diag_ignore_all (thanks Nathan) * using local scoping for code blocks instead of __VA_ARGS__ (thanks * Nick) * indented affected test cases (thanks Andy) changes from v2 -> v3: * reinserted commit message * remove Andy's Suggested-by tag * add issue tracker link changes from v3 -> v4: * better macro indentation and usage string (thanks Nick) lib/test_printf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/test_printf.c b/lib/test_printf.c index 07309c45f327..f78044c1efaa 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -30,6 +30,12 @@ #define PAD_SIZE 16 #define FILL_CHAR '$' =20 +#define NOWARN(option, comment, block) \ + __diag_push(); \ + __diag_ignore_all(#option, comment); \ + block \ + __diag_pop(); + KSTM_MODULE_GLOBALS(); =20 static char *test_buffer __initdata; @@ -154,9 +160,11 @@ test_number(void) test("0x1234abcd ", "%#-12x", 0x1234abcd); test(" 0x1234abcd", "%#12x", 0x1234abcd); test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0,= 1, 12, 123, 1234, -123, -1234); - test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1); - test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1); - test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627); + NOWARN(-Wformat, "Intentionally test narrowing conversion specifiers.", { + test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1); + test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1); + test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627); + }) /* * POSIX/C99: =C2=BBThe result of converting zero with an explicit * precision of zero shall be no characters.=C2=AB Hence the output --=20 2.37.0.170.g444d1eabd0-goog