From ad9dfe974ee12c4a56c0047eaabfb9e7ad642b28 Mon Sep 17 00:00:00 2001 From: Dmitry Babokin Date: Fri, 25 Oct 2024 00:42:08 -0700 Subject: [PATCH] Fix clang warning about printf format (#3814) Compiling with clang 16.0 on macOS I have warnings about incorrect printf format (see below). Values to be printed are `int64_t`, but they are printed with `%zu` and `%ld`, which are not portable way to print this type. ``` <...>/torch-mlir/test/CAPI/torch.c:52:3: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat] 52 | DEFINE_CHECK(NonValueTensor) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>/torch-mlir/test/CAPI/torch.c:37:13: note: expanded from macro 'DEFINE_CHECK' 36 | fprintf(stderr, #TTT "Type %s rank: %zu\n", testName, \ | ~~~ 37 | torchMlirTorch##TTT##TypeGetRank(TTT##Type)); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :78:1: note: expanded from here 78 | torchMlirTorchNonValueTensorTypeGetRank | ^ <...>/torch-mlir/test/CAPI/torch.c:52:3: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat] 52 | DEFINE_CHECK(NonValueTensor) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ <...>/torch-mlir/test/CAPI/torch.c:42:15: note: expanded from macro 'DEFINE_CHECK' 41 | fprintf(stderr, #TTT "Type %s pos %d size: %ld\n", testName, i, \ | ~~~ 42 | TTT##Sizes[i]); \ | ^~~~~~~~~~~~~ :85:1: note: expanded from here 85 | NonValueTensorSizes | ^ <...>/torch-mlir/test/CAPI/torch.c:53:3: warning: format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'int64_t' (aka 'long long') [-Wformat] 53 | DEFINE_CHECK(ValueTensor) | ^~~~~~~~~~~~~~~~~~~~~~~~~ <...>/torch-mlir/test/CAPI/torch.c:37:13: note: expanded from macro 'DEFINE_CHECK' 36 | fprintf(stderr, #TTT "Type %s rank: %zu\n", testName, \ | ~~~ 37 | torchMlirTorch##TTT##TypeGetRank(TTT##Type)); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :112:1: note: expanded from here 112 | torchMlirTorchValueTensorTypeGetRank | ^ <...>/torch-mlir/test/CAPI/torch.c:53:3: warning: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Wformat] 53 | DEFINE_CHECK(ValueTensor) | ^~~~~~~~~~~~~~~~~~~~~~~~~ <...>/torch-mlir/test/CAPI/torch.c:42:15: note: expanded from macro 'DEFINE_CHECK' 41 | fprintf(stderr, #TTT "Type %s pos %d size: %ld\n", testName, i, \ | ~~~ 42 | TTT##Sizes[i]); \ | ^~~~~~~~~~~~~ :119:1: note: expanded from here 119 | ValueTensorSizes | ^ 4 warnings generated. ``` --- test/CAPI/torch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CAPI/torch.c b/test/CAPI/torch.c index d42cf96d5..3d1308f08 100644 --- a/test/CAPI/torch.c +++ b/test/CAPI/torch.c @@ -33,12 +33,12 @@ static void testTensor(MlirContext ctx, intptr_t numSizes, int64_t *sizes, bool TTT##hasDtype = torchMlirTorch##TTT##TypeHasDtype(TTT##Type); \ fprintf(stderr, #TTT "Type %s hasDtype: %d\n", testName, TTT##hasDtype); \ if (TTT##hasSizes) { \ - fprintf(stderr, #TTT "Type %s rank: %zu\n", testName, \ + fprintf(stderr, #TTT "Type %s rank: %" PRId64 "\n", testName, \ torchMlirTorch##TTT##TypeGetRank(TTT##Type)); \ int64_t *TTT##Sizes = malloc(sizeof(int64_t) * numSizes); \ torchMlirTorch##TTT##TypeGetSizes(TTT##Type, TTT##Sizes); \ for (int i = 0; i < numSizes; ++i) { \ - fprintf(stderr, #TTT "Type %s pos %d size: %ld\n", testName, i, \ + fprintf(stderr, #TTT "Type %s pos %d size: %" PRId64 "\n", testName, i, \ TTT##Sizes[i]); \ } \ } \