Skip to content

Commit

Permalink
[mlir][CAPI][test] Change casts and fprintf format strings from long …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
zero9178 authored and arichardson committed Sep 12, 2021
2 parents 24df8dd + 09b5ebc commit 5ea52b1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mlir/test/CAPI/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mlir-c/Registration.h"

#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5ea52b1

Please sign in to comment.