diff mbox series

[v3,04/12] selftests/nolibc: fix up compile warning with glibc on x86_64

Message ID 0626464891e7fc938e6f7a55f1f475f31fbc6f37.1685777982.git.falcon@tinylab.org (mailing list archive)
State Accepted
Commit 0858aec4359636e539c6f26a1f3c9a3eceb87494
Headers show
Series nolibc: add generic part1 of prepare for rv32 | expand

Commit Message

Zhangjin Wu June 3, 2023, 8:05 a.m. UTC
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).

use a simple conversion to solve it.

Suggested-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/linux-riscv/20230529130449.GA2813@1wt.eu/
Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
---
 tools/testing/selftests/nolibc/nolibc-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index d417ca5d976f..403f6255c177 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -174,7 +174,7 @@  static int expect_eq(uint64_t expr, int llen, uint64_t val)
 {
 	int ret = !(expr == val);
 
-	llen += printf(" = %lld ", expr);
+	llen += printf(" = %lld ", (long long)expr);
 	pad_spc(llen, 64, ret ? "[FAIL]\n" : " [OK]\n");
 	return ret;
 }