[Mlir-commits] [mlir] [mlir][capi] Fix non-portable int64_t printf formatting in greedy rewrite config test (PR #175487)
Alexandre Eberhardt
llvmlistbot at llvm.org
Sun Jan 11 21:26:11 PST 2026
https://github.com/alexandreeberhardt created https://github.com/llvm/llvm-project/pull/175487
This PR fixes non-portable `printf` formatting in the GreedyRewriteDriverConfig C-API test.
### Problem
The test prints `int64_t` values using `%ld`. This is not portable on LLP64 platforms (Windows or some MacOS configurations), where `long` is 32-bit, which can truncate values or lead to undefined behavior.
### Fix
- Include `<inttypes.h>`
- Print `int64_t` values using the `PRId64` macro:
- `%" PRId64 "`
### Testing
- `ninja check-mlir`
>From 8af049dff7dd2c24b3449d972f4cc19bec180ba7 Mon Sep 17 00:00:00 2001
From: alexandre <alexandre.eber07 at gmail.com>
Date: Mon, 12 Jan 2026 00:20:22 -0500
Subject: [PATCH] [mlir][capi] Fix non-portable int64_t printf formatting in
greedy rewrite config test
The C-API test prints int64_t values using %ld, which is not portable on LLP64
platforms (Windows or some MacOS configurations) where long is 32-bit. Use <inttypes.h> and PRId64 to
print int64_t portably.
Test: ninja check-mlir
---
mlir/test/CAPI/rewrite.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mlir/test/CAPI/rewrite.c b/mlir/test/CAPI/rewrite.c
index 0745eb496c1d7..5795646be544f 100644
--- a/mlir/test/CAPI/rewrite.c
+++ b/mlir/test/CAPI/rewrite.c
@@ -14,8 +14,10 @@
#include "mlir-c/IR.h"
#include <assert.h>
+#include <inttypes.h>
#include <stdio.h>
+
MlirOperation createOperationWithName(MlirContext ctx, const char *name) {
MlirStringRef nameRef = mlirStringRefCreateFromCString(name);
MlirLocation loc = mlirLocationUnknownGet(ctx);
@@ -554,10 +556,10 @@ void testGreedyRewriteDriverConfig(MlirContext ctx) {
// Test all configuration getters and verify values
// CHECK: MaxIterations: 5
- fprintf(stderr, "MaxIterations: %ld\n",
+ fprintf(stderr, "MaxIterations: %" PRId64 "\n",
mlirGreedyRewriteDriverConfigGetMaxIterations(config));
// CHECK: MaxNumRewrites: 100
- fprintf(stderr, "MaxNumRewrites: %ld\n",
+ fprintf(stderr, "MaxNumRewrites: %" PRId64 "\n",
mlirGreedyRewriteDriverConfigGetMaxNumRewrites(config));
// CHECK: UseTopDownTraversal: 1
fprintf(stderr, "UseTopDownTraversal: %d\n",
More information about the Mlir-commits
mailing list