[Mlir-commits] [mlir] [mlir][capi] Fix non-portable int64_t printf formatting in greedy rewrite config test (PR #175487)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jan 11 21:26:58 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Alexandre Eberhardt (alexandreeberhardt)

<details>
<summary>Changes</summary>

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`


---
Full diff: https://github.com/llvm/llvm-project/pull/175487.diff


1 Files Affected:

- (modified) mlir/test/CAPI/rewrite.c (+4-2) 


``````````diff
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",

``````````

</details>


https://github.com/llvm/llvm-project/pull/175487


More information about the Mlir-commits mailing list