[Mlir-commits] [mlir] d9e4309 - [mlir][NFC] Fix format specifier warning on Windows

Markus Böck llvmlistbot at llvm.org
Fri Feb 23 03:50:35 PST 2024


Author: Markus Böck
Date: 2024-02-23T12:50:33+01:00
New Revision: d9e4309b451c1b24d4e0a6304057663b877e5266

URL: https://github.com/llvm/llvm-project/commit/d9e4309b451c1b24d4e0a6304057663b877e5266
DIFF: https://github.com/llvm/llvm-project/commit/d9e4309b451c1b24d4e0a6304057663b877e5266.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/test/CAPI/llvm.c

Removed: 
    


################################################################################
diff  --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 5a78fac91a5097..1817988dd67dd6 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -15,6 +15,7 @@
 #include "mlir-c/Support.h"
 
 #include <assert.h>
+#include <inttypes.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -105,7 +106,7 @@ static int testStructTypeCreation(MlirContext ctx) {
   // CHECK: i8
   // CHECK: i32
   // CHECK: i64
-  fprintf(stderr, "num elements: %ld\n",
+  fprintf(stderr, "num elements: %" PRIdPTR "\n",
           mlirLLVMStructTypeGetNumElementTypes(literal));
   for (intptr_t i = 0; i < 3; ++i) {
     mlirTypeDump(mlirLLVMStructTypeGetElementType(literal, i));


        


More information about the Mlir-commits mailing list