Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3139103rwd; Mon, 29 May 2023 06:18:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HHPDZoWv/CnjD+p5zcBJFE9LxCOQ9xnjgpSPir6HsgzE4BcbzuArNZiJ5q31IG04m1A2v X-Received: by 2002:a05:6a20:3d88:b0:10b:7b22:cbf1 with SMTP id s8-20020a056a203d8800b0010b7b22cbf1mr10478823pzi.7.1685366326703; Mon, 29 May 2023 06:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685366326; cv=none; d=google.com; s=arc-20160816; b=ea0XLjta09MKeEgC4dKyrU9gttM1HIjFk8KDLhB+Ssi5E/vHYoRzydiS30R+Rw4n3f iuNnDQ3QfphssxQn5tnZy8VvOH8G5MO/W91M7df6RQf1UzkW8+jwCRMN4Axa8feLf2/n BtaRRVeMqjh7s98wV4dHt86gx6sjesm21kiCKXRNNMqwfakvXx79oc88MBd6H+/WOn6Z BMJUfQDOzXTQvi6BjevolgxusmhMIfUYQLs0VpAP/8yovDOY28QUUOO/EjKmzqb35kG9 A8BHOMc7th+EFFZRoOQRZNkHPbDkDg/uTkP+haHMbyYt2GyGfRMF9ljY4jk9O0CkUVCk 2zpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=L6ucqjGF9GbLiL45pB+Rxa0NO53E2PdRiEHPNIh9V6g=; b=xhB9kVFcsNDyTMhksOQIfdG8N2yTnAwFzBChoymFGN18DSkc/YNWYiFSddqlKQ/5lD hdESw7xXamQ2R/elgsWKrOBSFLaMF4aBMwPh9iGvWxYDr9CLnCIiaOvTFHEpYgjacaS9 k/EpWqUGvrquAjky5fH0yhA5gZXa6Oe3RIY5MV4ROgw1dXrbPq2/dvXkZ/4fThlDotuv HlC4iVcbOwj33blA+Ex5Es96zTCMyB2O4VOyJzJFuHivp3nPbDMP4am2Ork719kiPJDM 2jK7NCtvpG2nzU3o0BjUo6nh39DD9wIAgz0467nSF8jgi+3w5ySJT8PjvZgXQkaf3SV1 Qz3A== 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 o27-20020a63921b000000b00534919b4ca2si8720120pgd.151.2023.05.29.06.18.34; Mon, 29 May 2023 06:18:46 -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 S229698AbjE2NRR (ORCPT + 99 others); Mon, 29 May 2023 09:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjE2NRN (ORCPT ); Mon, 29 May 2023 09:17:13 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CFAC10C; Mon, 29 May 2023 06:16:37 -0700 (PDT) X-QQ-mid: bizesmtp79t1685366138tuh7hwm2 Received: from linux-lab-host.localdomain ( [119.123.130.80]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 29 May 2023 21:15:37 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: Bt6VvACH2lxPDSqLKk8oIpBVhB33MD55CoUCVpzQ9ygXQNimNUvEkUlPf0ILF XgQDDzZu334LYd4VWLUHTb6l5t44PodGFC44Sj9m29ix6L3usWzz7F1hY5HpmH/TZAJFAhv webS86/IrzS4fW/ZYl6eR/LRpVClD+cdFOF190p35yX6rNGT6tEYUg3B+mMLG8fewYgR0NM 6iVECGjzITrPvUjBPEK7TB2sibfaEs5093+0IqA7CHieBb4Y02XfJXtetvVxZ5XuGsZfwMi NzBDvh64IRFpTUsY4fjqEncEl/hqCw6A+guWHJc0Bs3QLOGrPJDU7o4E83ypK7S3XIkXUBW TdnU7W4QhefRz/kSCAIksuSE/RqIy/bo/jXAITzMZrdgTr4sqPvuuYIJi2wIw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1046913872741626693 From: Zhangjin Wu To: w@1wt.eu Cc: arnd@arndb.de, falcon@tinylab.org, 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 Date: Mon, 29 May 2023 21:15:36 +0800 Message-Id: <20230529131536.80183-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230529130449.GA2813@1wt.eu> References: <20230529130449.GA2813@1wt.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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); Yes, this conversion is better, my method make things more complex ;-) Thanks, Zhangjin > > Willy