Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3810725imw; Mon, 18 Jul 2022 15:07:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYRKgw0IWoVmK16ah/7tmTnnLb8Cricy+xdlEKxCnNcg7GDfo8VNtavppUmt/3mIi2+8KA X-Received: by 2002:a05:6870:d206:b0:10c:2628:d042 with SMTP id g6-20020a056870d20600b0010c2628d042mr18882798oac.157.1658182028105; Mon, 18 Jul 2022 15:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658182028; cv=none; d=google.com; s=arc-20160816; b=tN5lZ2TQge3v3kIEaSPZQGf19If8sdA76X3KZRIcdCme+CPFGGFBRw7WIkaHxqHZwP MC/eacNRLmc1edAQ3XIN4TYrHQuObx/HAtY9TE/BKNKSeg4iNElG2sjerfiGtjxjdS9D 9Ov1bawpSEZcOs2uENE/UZUiAyc7rYT9K5MJ6BSuHl6Ltw4HponT8GGJqpLcKCZgWoLO X2sy3nqzjgG9ZTVYFxW6AT0v+tVKeEgjheVpDoPJ5X8MZACPbqghby9GgKZLVZpYCf6o Y5DcElMFgXWlhgRqWEUYkUo2VNDagpBmkO3th+8SNo1oZZ95RiBk8HHR8VKCu4/6VetX 3q7w== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4LCLHgQVQuXh0W/cqwPKu45ik98XylTXSBFO2vmTL+g=; b=DkcW5ol4clYHOtMu3Td4TGCBfuP1HfTVmQPRosQEoc1UVsI5kGI9Rc1a4vvmcXx8oU b3h8KXt7K5ptcXPtXjEuR9+ffps3757eooUtBz74hBwWxxySeYy9IKvp7KqExlnAl6o4 7HRMx5qgSnQNC0R5/s6iv3WivNhKTtbiQZStBnneNiGNHO1OCFK4zljRDbfBlbJfN9yd hS2crqcWyygtDZiUWg6TxgwvuFWiPgpldHinUvtKWXE+/+WJouZioAy3LYyg2hzAZXyn Ck+80FYwjfJfXo0ro3xReRPPybxdvRb9jD7z93pAWB1cMj/mpkVP/c3aLw9Bf9/4iq1M mx1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=j5ZRqt6b; 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 a3-20020a4a8dc3000000b0043559b57c5dsi8068278ool.77.2022.07.18.15.06.54; Mon, 18 Jul 2022 15:07:08 -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=j5ZRqt6b; 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 S236402AbiGRWAk (ORCPT + 99 others); Mon, 18 Jul 2022 18:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233142AbiGRWAi (ORCPT ); Mon, 18 Jul 2022 18:00:38 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A5530569 for ; Mon, 18 Jul 2022 15:00:37 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id u13so21721027lfn.5 for ; Mon, 18 Jul 2022 15:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=4LCLHgQVQuXh0W/cqwPKu45ik98XylTXSBFO2vmTL+g=; b=j5ZRqt6bbWc4wkqolT6AXcJVpi/kkId/WpIKSB2kv3l3leT/RFiY1Juj3mdIudCBHP V2fxKSqCETby/Ndly0e/sKtL5++LF3KC6mRb5hprroZZcMk7KgUr/nmfXNGBU+IXo7/f Lj4wmEYEV7OcorVp315Zwmf45QIVssR3yFJSOTHAh1iFlnWIybUtVwyf5KPMplWED1I3 KcifCpwyCcwMs56wjcCQn8TY26dkay+B4YTNt2dCbeR4sq6O/KwYd1NuPMm1bCnqZC/+ CS9GyvMNmcEthsrj0qBLy/pkdVJacJ48CW8C2KNON0AnERavShMGU38d4z+TDU2SB0+s 2mGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4LCLHgQVQuXh0W/cqwPKu45ik98XylTXSBFO2vmTL+g=; b=TE38IqsOw+f84VFf0UpQrgnA/zy0TPihFR/GYu0gTZBwN2RHaYviJnvqNMkRRFP6Vy cQqSEGYXYPgGArdPFBZDBB6XEz7CKBjKB7H/0q4yoMk+rv/yLmidzX0hhqtMhAHJIfHn AiPRMoHIkkyNwxpeP6NhpOyDxA4ts6nQomnoDTEw8/MEniwLlvRXx1gc440ww7qzlLvz 8ihgNuz+ETkU6h6pCDVIYOBpjbxxnwtyYZ31X1h/h3r5Z1d3Ky1ZNVrEA5FuBO2E4ZPG 4ilTHPUAnTGba0HHwXGp78mUn+lHP152agyVM65MeTfWJm1nUHUZoRJi2/x/UmaKUDmb Z6xQ== X-Gm-Message-State: AJIora8VmRTK4fbQH/AVRPplJdqlhGe3N4s2exkhQYeCyBHaZ8H3PpDu y31m+P1fOnbh0SRl8OHdqUPIzM+sIB/c1ME9DwXF0A== X-Received: by 2002:a05:6512:e9a:b0:489:c681:da2b with SMTP id bi26-20020a0565120e9a00b00489c681da2bmr15211089lfb.626.1658181635855; Mon, 18 Jul 2022 15:00:35 -0700 (PDT) MIME-Version: 1.0 References: <20220629235326.480858-1-justinstitt@google.com> <20220718172934.4155189-1-justinstitt@google.com> In-Reply-To: <20220718172934.4155189-1-justinstitt@google.com> From: Nick Desaulniers Date: Mon, 18 Jul 2022 15:00:24 -0700 Message-ID: Subject: Re: [PATCH v3] lib/test_printf.c: fix clang -Wformat warnings To: Justin Stitt Cc: andriy.shevchenko@linux.intel.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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 /On Mon, Jul 18, 2022 at 10:29 AM Justin Stitt wro= te: > > 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 > > lib/test_printf.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/lib/test_printf.c b/lib/test_printf.c > index 07309c45f327..1b1755ce9fa7 100644 > --- a/lib/test_printf.c > +++ b/lib/test_printf.c > @@ -30,6 +30,9 @@ > #define PAD_SIZE 16 > #define FILL_CHAR '$' > > +#define NOWARN(option, comment, block) \ > + __diag_push() __diag_ignore_all(#option, comment) block _= _diag_pop() Do you mind putting these 4 on distinct lines with \ at the end of the lines, and terminate the statements with an additional ; if that doesn't produce new warnings about empty statements? Maybe something like: +#define NOWARN(option, comment, block) \ + __diag_push(); \ + __diag_ignore_all(#option, comment); \ + block \ + __diag_pop(); (sorry for not formatting that myself, remember to use tabs vs spaces). To me, it seems more readable from a quick glance to have these be distinct lines. You'll find open coded uses of __diag_push and friends add the semicolon, even if not strictly necessary. > + > KSTM_MODULE_GLOBALS(); > > static char *test_buffer __initdata; > @@ -154,9 +157,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, "Disables clang -Wformat warning", { Technically, this is disabling -Wformat for all compilers. How about a comment string like "Intentionally test narrowing conversion specifiers"? > + test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 2= 57, 128, -1); > + test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 2= 57, 128, -1); > + test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627= ); > + }) > /* > * POSIX/C99: =C2=BBThe result of converting zero with an explici= t > * precision of zero shall be no characters.=C2=AB Hence the outp= ut > -- > 2.37.0.rc0.161.g10f37bed90-goog > --=20 Thanks, ~Nick Desaulniers