[Mlir-commits] [mlir] 09b5ebc - [mlir][CAPI][test] Change casts and fprintf format strings from long to intptr_t

Markus Böck llvmlistbot at llvm.org
Tue May 25 08:49:02 PDT 2021


Author: Markus Böck
Date: 2021-05-25T17:48:54+02:00
New Revision: 09b5ebc07b477e7e115299cf42fe7737736dd5da

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

LOG: [mlir][CAPI][test] Change casts and fprintf format strings from long to intptr_t

A test in ir.c makes use of casting a void* to an integer type to print it's address. This cast is currently done with the datatype `long` however, which is only guaranteed to be equal to the pointer width on LP64 system. Other platforms may use a length not equal to the pointer width. 64bit Windows as an example uses 32 bit for `long` which does not match the 64 bit pointers.
This also results in clang warning due to `-Wvoid-pointer-to-int-cast`.

Technically speaking, since the test only passes the value 42, it does not cause any issues, but it'd be nice to fix the warning at least.

Differential Revision: https://reviews.llvm.org/D103085

Added: 
    

Modified: 
    mlir/test/CAPI/ir.c

Removed: 
    


################################################################################
diff  --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index e3782064658c6..ac8a0dc266870 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -21,6 +21,7 @@
 #include "mlir-c/Registration.h"
 
 #include <assert.h>
+#include <inttypes.h>
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1597,7 +1598,7 @@ int testOperands() {
 
   // Test operand APIs.
   intptr_t numOperands = mlirOperationGetNumOperands(op);
-  fprintf(stderr, "Num Operands: %ld\n", numOperands);
+  fprintf(stderr, "Num Operands: %" PRIdPTR "\n", numOperands);
   // CHECK: Num Operands: 1
 
   MlirValue opOperand = mlirOperationGetOperand(op, 0);
@@ -1653,19 +1654,22 @@ int testClone() {
 
 // Wraps a diagnostic into additional text we can match against.
 MlirLogicalResult errorHandler(MlirDiagnostic diagnostic, void *userData) {
-  fprintf(stderr, "processing diagnostic (userData: %ld) <<\n", (long)userData);
+  fprintf(stderr, "processing diagnostic (userData: %" PRIdPTR ") <<\n",
+          (intptr_t)userData);
   mlirDiagnosticPrint(diagnostic, printToStderr, NULL);
   fprintf(stderr, "\n");
   MlirLocation loc = mlirDiagnosticGetLocation(diagnostic);
   mlirLocationPrint(loc, printToStderr, NULL);
   assert(mlirDiagnosticGetNumNotes(diagnostic) == 0);
-  fprintf(stderr, "\n>> end of diagnostic (userData: %ld)\n", (long)userData);
+  fprintf(stderr, "\n>> end of diagnostic (userData: %" PRIdPTR ")\n",
+          (intptr_t)userData);
   return mlirLogicalResultSuccess();
 }
 
 // Logs when the delete user data callback is called
 static void deleteUserData(void *userData) {
-  fprintf(stderr, "deleting user data (userData: %ld)\n", (long)userData);
+  fprintf(stderr, "deleting user data (userData: %" PRIdPTR ")\n",
+          (intptr_t)userData);
 }
 
 void testDiagnostics() {


        


More information about the Mlir-commits mailing list