Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3135190rwd; Mon, 29 May 2023 06:15:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nJHW8tHszb7hssZ0/vR3CPfNKdHrp/KG9ACPChmpuwiIInsy/dPyFCxVcY/Cx3Ad7bVWW X-Received: by 2002:a05:6a20:1453:b0:101:282c:2b with SMTP id a19-20020a056a20145300b00101282c002bmr9913531pzi.32.1685366156634; Mon, 29 May 2023 06:15:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685366156; cv=none; d=google.com; s=arc-20160816; b=vaL6a7H74WKxI01Zz4niXbEM8gxdF1ytrajLsTE1VjO5AIL9q68f8wZfnC1XzONnVv ZBOI+sQPvna06xmXU77gGkd2hAKQOY19yHv+sPmJMbWUoNVEfQ94s7A2Qja/APF6IK4A QvuV4LZbQQSPzuAeB0Mfg8tXrKvJ+ls5Q8ZLH+hIX5D15L8tv5bCfAJxB8PCGsvuH19g f+FjIoItfC8P4SZXd5CaVgyudFZe8NuJJELK0xFsyD9fVZ1ZJO5bDjer+3TKinvN//pD pha+EbbCDT+6bciKpSds07cDywhZN8bhLF9udbPWnd/bHN1VI654YcigIu95/10san6N x5mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=7K7zHpFsGAh0gxz/yMFdR8EI8etc1+KUR+UdU7BxdTY=; b=noAo290krtuyBdGOd3sKQn0ppUV3O9WdQjHH3sqANBzA/pdoW6WFlhnCV2nYP49VEi iQs1GxAcJTeG4M8yaQNAHgfZWbFesHaMsHUIFJc3z1ln//AaNIJTOzCrC+44mVPWnuEW l0L/u7eVuq56gqxq+3JQz6WnVaEgVSSbEGWk5Jx67B/YcWhP0A3SA33fHb2ln1Vdi+6B aZtDnqerkYIgPdKav3cS/pn3qYmtTnQu8CtuGbhWC+WQ4GstFnhsUwZEaMu44Oh6IZjC hxT7gwq0aC1anzcf7knCf5IZQnSZxKI89yRMs2PVTn6HLgS4ToGHDYawirow3ut2/ywv RB7A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r23-20020a638f57000000b00535f192eac7si9093181pgn.211.2023.05.29.06.15.43; Mon, 29 May 2023 06:15:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjE2NFn (ORCPT + 99 others); Mon, 29 May 2023 09:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjE2NFR (ORCPT ); Mon, 29 May 2023 09:05:17 -0400 Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02B4BD8; Mon, 29 May 2023 06:05:13 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 34TD4ndg002822; Mon, 29 May 2023 15:04:49 +0200 Date: Mon, 29 May 2023 15:04:49 +0200 From: Willy Tarreau To: Zhangjin Wu Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, thomas@t-8ch.de Subject: Re: [PATCH v2 3/7] selftests/nolibc: fix up compile warning with glibc on x86_64 Message-ID: <20230529130449.GA2813@1wt.eu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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, May 29, 2023 at 09:00:01PM +0800, Zhangjin Wu wrote: > Compiling nolibc-test.c with gcc on x86_64 got such warning: > > tools/testing/selftests/nolibc/nolibc-test.c: In function 'expect_eq': > tools/testing/selftests/nolibc/nolibc-test.c:177:24: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'uint64_t' {aka 'long unsigned int'} [-Wformat=] > 177 | llen += printf(" = %lld ", expr); > | ~~~^ ~~~~ > | | | > | | uint64_t {aka long unsigned int} > | long long int > | %ld > > It because that glibc defines uint64_t as "unsigned long int" when word > size (means sizeof(long)) is 64bit (see include/bits/types.h), but > nolibc directly use the 64bit "unsigned long long" (see > tools/include/nolibc/stdint.h), which is simpler, seems kernel uses it > too (include/uapi/asm-generic/int-ll64.h). > > It is able to do like glibc, defining __WORDSIZE for all of platforms > and using "unsigned long int" to define uint64_t when __WORDSIZE is > 64bits, but here uses a simpler solution: nolibc always requires %lld to > match "unsigned long long", for others, only require %lld when word size > is 32bit. > > Signed-off-by: Zhangjin Wu > --- > tools/testing/selftests/nolibc/nolibc-test.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c > index d417ca5d976f..7f9b716fd9b1 100644 > --- a/tools/testing/selftests/nolibc/nolibc-test.c > +++ b/tools/testing/selftests/nolibc/nolibc-test.c > @@ -174,7 +174,11 @@ static int expect_eq(uint64_t expr, int llen, uint64_t val) > { > int ret = !(expr == val); > > +#if __SIZEOF_LONG__ == 4 || defined(NOLIBC) > llen += printf(" = %lld ", expr); > +#else > + llen += printf(" = %ld ", expr); > +#endif > pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n"); > return ret; > } Please don't proceed like this. There's much easier to do here for a printf, just cast the expression to the type printf expects: - llen += printf(" = %lld ", expr); + llen += printf(" = %lld ", (long long)expr); Willy