Received: by 2002:a05:6358:615c:b0:12b:e873:ff31 with SMTP id 28csp3677602rwt; Fri, 4 Aug 2023 08:08:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrJD9OFErN+48um7PRbHIDqYJ24hhxeGFI9OJIC2bb6XfBa12DNrwC0/GXg8l6PQOc8Niw X-Received: by 2002:a17:902:a40b:b0:1bb:5d9a:9054 with SMTP id p11-20020a170902a40b00b001bb5d9a9054mr2127785plq.12.1691161735621; Fri, 04 Aug 2023 08:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691161735; cv=none; d=google.com; s=arc-20160816; b=F6wrkYCX+BP1AqX0CLFZAywMWkiI9oHKqlR8zNWL1/ss8cHiIx20jTUQ2wblV2Wv+Y ihi9p/5ZFmyQdKGlls/7mhyZb7dktoAcGsar80CEGYbUtBXS293+J15VpOc3zPOoxwzp Z0GpfpUWkrWCJtOlYFNVriwMZnt4JnNCrUTRrzrIOY0pI5ruG3w5Wq9bL+loYY54fLW9 qlSFch2T5SkDN73OuPxy4mWMENFgopcnhs0cefARD+3MQ85bdB4WvZvSyJGS/03sSQwo N+xkLxcoVh6IOZ+ZYmXL5A34JIbgygnoHq8Fh3y8JEDeLsCNDnAfq3don+F6AHw4hcsz yGQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=g0Hz+F2MmQpyyG1GOU9s65qSSOLInCJN5VnM3grXm8c=; fh=TgYnRoMzaEcxIJTKV+TieuOIlo2lNhW8umIcK9Q1Lic=; b=BA+CfoERChgQjjRT05JKQnqUoFWX8Z43bOFNMw1dMH4SlajrhG/DCiyX9C9BVtg2tb hPOAfqeI1cprJoWTiHrbDY/FgX+BVDqFZqjlgRwsMesPTNXlboaV01RXivnU4umB6dNE mF7XFuqihNC9C21JcXGEFH3A9TVKI6QoPp+X0WhmS7SorFTApHy9owsMPw1Hk4cB4CqJ QJ65sdxm3p1QNLsNuFf6goBcABcvitNZ3Id/b9pQvPOBOjikrVyvJywVr/U007T7CNTg hbRT8CNokC/4UdCQhL9uNHXPzq6sPGNq4w6HkeyKPjPKXsGqf+oSEoToeIIoDfSNb6PJ INWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nABWueLb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kr13-20020a170903080d00b001b88ff83e45si1775193plb.571.2023.08.04.08.08.28; Fri, 04 Aug 2023 08:08:55 -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=@kernel.org header.s=k20201202 header.b=nABWueLb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231737AbjHDOtE (ORCPT + 99 others); Fri, 4 Aug 2023 10:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbjHDOtD (ORCPT ); Fri, 4 Aug 2023 10:49:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED5E949C1 for ; Fri, 4 Aug 2023 07:49:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7E65960C58 for ; Fri, 4 Aug 2023 14:49:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52AF6C433C9; Fri, 4 Aug 2023 14:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691160541; bh=xQy0735LbfWCkytz1dXsO/muUeNMgiKlX1anJPkBEHA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nABWueLbmtLzqyKR8KGQBt4dq+v1tebs0Y/Wal5qtcKyPqnR3CKFbEoO94AiCqY3d yHUP83Dpi2ywalDYsdGEJy3HNXenf59G/4yB33p41bi2iqD/uibNtdNh1rKBDqwVab VSen3p2K42vvLa0MAEZazwEM7LBV5sICPs0lfqVOtiYsf7RcJEAAR5hrDolRBcQG9Z JZ3tJ21qi+N8VWoL6pIkTF+21f9UNTyA1f176ocEVZLEqqqZvQG3tAWrkiV2KUBfg1 KTUOAnAM9l/CGkucfhW8VUqLtg3gbB5+76yLi05wIFORbl0XhiNQ3qiBBAvVbIlY0q ZysMW50RzNp8w== Date: Fri, 4 Aug 2023 07:48:59 -0700 From: Nathan Chancellor To: Andy Shevchenko Cc: pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org, linux@rasmusvillemoes.dk, ndesaulniers@google.com, trix@redhat.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, patches@lists.linux.dev Subject: Re: [PATCH] lib: test_scanf: Add explicit type cast to result initialization in test_number_prefix() Message-ID: <20230804144859.GA3027708@dev-arch.thelio-3990X> References: <20230803-test_scanf-wconstant-conversion-v1-1-74da994dedbc@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 Fri, Aug 04, 2023 at 07:25:00AM +0300, Andy Shevchenko wrote: > On Thu, Aug 03, 2023 at 11:14:42AM -0700, Nathan Chancellor wrote: > > A recent change in clang allows it to consider more expressions as > > compile time constants, which causes it to point out an implicit > > conversion in the scanf tests: > > > > lib/test_scanf.c:661:2: warning: implicit conversion from 'int' to 'unsigned char' changes value from -168 to 88 [-Wconstant-conversion] > > 661 | test_number_prefix(unsigned char, "0xA7", "%2hhx%hhx", 0, 0xa7, 2, check_uchar); > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > lib/test_scanf.c:609:29: note: expanded from macro 'test_number_prefix' > > 609 | T result[2] = {~expect[0], ~expect[1]}; \ > > | ~ ^~~~~~~~~~ > > 1 warning generated. > > > > The result of the bitwise negation is the type of the operand after > > going through the integer promotion rules, so this truncation is > > expected but harmless, as the initial values in the result array get > > overwritten by _test() anyways. Add an explicit cast to the expected > > type in test_number_prefix() to silence the warning. There is no > > functional change, as all the tests still pass with GCC 13.1.0 and clang > > 18.0.0. > > > do { \ > > const T expect[2] = { expect0, expect1 }; \ > > - T result[2] = {~expect[0], ~expect[1]}; \ > > + T result[2] = {(T)~expect[0], (T)~expect[1]}; \ > > Can we add spaces as above, while at it? > > T result[2] = { (T)~expect[0], (T)~expect[1] }; \ Sure. I can send a v2 on Monday to give folks a chance to chime in with other comments. > > _test(fn, &expect, str, scan_fmt, n_args, &result[0], &result[1]); \ > > } while (0) > > -- > With Best Regards, > Andy Shevchenko > >