Skip to content

Commit d9e4309

Browse files
committed
[mlir][NFC] Fix format specifier warning on Windows
`%ld` specifier is defined to work on values of type `long`. The parameter given to `fprintf` is of type `intptr_t` whose actual underlying integer type is unspecified. On Unix systems it happens to commonly be `long` but on 64-bit Windows it is defined as `long long`. The cross-platform way to print a `intptr_t` is to use `PRIdPTR` which expands to the correct format specifier for `intptr_t`. This avoids any undefined behaviour and compiler warnings.
1 parent 3dfca24 commit d9e4309

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mlir/test/CAPI/llvm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mlir-c/Support.h"
1616

1717
#include <assert.h>
18+
#include <inttypes.h>
1819
#include <math.h>
1920
#include <stdio.h>
2021
#include <stdlib.h>
@@ -105,7 +106,7 @@ static int testStructTypeCreation(MlirContext ctx) {
105106
// CHECK: i8
106107
// CHECK: i32
107108
// CHECK: i64
108-
fprintf(stderr, "num elements: %ld\n",
109+
fprintf(stderr, "num elements: %" PRIdPTR "\n",
109110
mlirLLVMStructTypeGetNumElementTypes(literal));
110111
for (intptr_t i = 0; i < 3; ++i) {
111112
mlirTypeDump(mlirLLVMStructTypeGetElementType(literal, i));

0 commit comments

Comments
 (0)