Skip to content

[mlir-c] Fix pattern-set leak in rewrite.c materialization tests - #211358

Merged
makslevental merged 1 commit into
mainfrom
users/makslevental/fix-capi-rewrite-materialization-leak
Jul 22, 2026
Merged

[mlir-c] Fix pattern-set leak in rewrite.c materialization tests#211358
makslevental merged 1 commit into
mainfrom
users/makslevental/fix-capi-rewrite-materialization-leak

Conversation

@makslevental

@makslevental makslevental commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The TypeConverter materialization tests added in #208934 (testTypeConverterSourceMaterialization / testTypeConverterTargetMaterialization) freeze their MlirRewritePatternSet but never destroy it.

This was caught by LeakSanitizer on the aarch64 HWASan bootstrap bot (builder 55, build 30763):

Fix: call mlirRewritePatternSetDestroy(patterns) after freezing in both tests, matching existing usage.

Assisted by: Claude

The materialization tests added in #208934 freeze their MlirRewritePatternSet
but never destroy it. mlirFreezeRewritePattern only moves the patterns out of
the heap-allocated RewritePatternSet; the container itself must still be freed
with mlirRewritePatternSetDestroy (as testConversionTargetDynamicLegality
already does). The leak was caught by LeakSanitizer on the aarch64 HWASan
bootstrap bot (builder 55).
@makslevental

makslevental commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@makslevental
makslevental marked this pull request as ready for review July 22, 2026 21:28
@makslevental
makslevental requested review from PragmaTwice, jpienaar and kuhar and removed request for jpienaar July 22, 2026 21:36
@makslevental
makslevental merged commit 1ba2d93 into main Jul 22, 2026
16 checks passed
@makslevental
makslevental deleted the users/makslevental/fix-capi-rewrite-materialization-leak branch July 22, 2026 22:02
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

The TypeConverter materialization tests added in #208934 (testTypeConverterSourceMaterialization / testTypeConverterTargetMaterialization) freeze their MlirRewritePatternSet but never destroy it.

This was caught by LeakSanitizer on the aarch64 HWASan bootstrap bot (builder 55, build 30763):

Fix: call mlirRewritePatternSetDestroy(patterns) after freezing in both tests, matching existing usage.

Assisted by: Claude


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

1 Files Affected:

  • (modified) mlir/test/CAPI/rewrite.c (+2)
diff --git a/mlir/test/CAPI/rewrite.c b/mlir/test/CAPI/rewrite.c
index 03cde15165c8a..230ae58fd23ba 100644
--- a/mlir/test/CAPI/rewrite.c
+++ b/mlir/test/CAPI/rewrite.c
@@ -911,6 +911,7 @@ void testTypeConverterSourceMaterialization(MlirContext ctx) {
   mlirRewritePatternSetAdd(patterns,
                            mlirConversionPatternAsRewritePattern(pattern));
   MlirFrozenRewritePatternSet frozen = mlirFreezeRewritePattern(patterns);
+  mlirRewritePatternSetDestroy(patterns);
 
   MlirConversionTarget target = mlirConversionTargetCreate(ctx);
   mlirConversionTargetAddIllegalOp(
@@ -1002,6 +1003,7 @@ void testTypeConverterTargetMaterialization(MlirContext ctx) {
   mlirRewritePatternSetAdd(patterns,
                            mlirConversionPatternAsRewritePattern(pattern));
   MlirFrozenRewritePatternSet frozen = mlirFreezeRewritePattern(patterns);
+  mlirRewritePatternSetDestroy(patterns);
 
   MlirConversionTarget target = mlirConversionTargetCreate(ctx);
   mlirConversionTargetAddIllegalOp(

midhuncodes7 pushed a commit to midhuncodes7/llvm-project that referenced this pull request Jul 28, 2026
…m#211358)

The `TypeConverter` materialization tests added in llvm#208934 (`testTypeConverterSourceMaterialization` / `testTypeConverterTargetMaterialization`) freeze their `MlirRewritePatternSet` but never destroy it.

This was caught by LeakSanitizer on the aarch64 HWASan bootstrap bot ([builder 55, build
30763](https://lab.llvm.org/buildbot/#/builders/55/builds/30763)):

Fix: call `mlirRewritePatternSetDestroy(patterns)` after freezing in both tests, matching existing usage.

Assisted by: Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant