From 4d7e653b523027ffb67a6ee7e439392431cbee2d Mon Sep 17 00:00:00 2001 From: Razvan Lupusoru Date: Mon, 13 Jul 2026 17:02:05 -0700 Subject: [PATCH] [mlir][acc] Fix leaks in cg unit tests (#209339) Newly added tests are failing valgrind --leak-check=full: https://github.com/llvm/llvm-project/pull/209313 https://github.com/llvm/llvm-project/pull/209316 This PR resolves the problem by ensuring that the insertion point is set into an operation that is owned and deleted by the test. --- mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp | 7 +++++++ mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp | 6 ++++++ .../Dialect/OpenACC/OpenACCUtilsReductionTest.cpp | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp index 6de57c9801f9..66e500c4d210 100644 --- a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp +++ b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsCGTest.cpp @@ -458,6 +458,7 @@ TEST_F(OpenACCUtilsCGTest, getPrivatizeOpFromHandle) { TEST_F(OpenACCUtilsCGTest, getPrivatizeOpFromComputeRegionBlockArg) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr gangDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::blockXDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -540,6 +541,7 @@ TEST_F(OpenACCUtilsCGTest, collectPrivateLocalParDimsFromLaunchFallback) { // With no enclosing parallel loops, collectPrivateLocalParDims falls back to // the block-level launch dimensions. OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr gangDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::blockXDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -678,6 +680,7 @@ TEST_F(OpenACCUtilsCGTest, collectPrivateLocalParDimsFromReductionUsers) { TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateGangPrivate) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr gangDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::blockXDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -699,6 +702,7 @@ TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateGangPrivate) { TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateThreadXPrivate) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr vectorDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::threadXDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -721,6 +725,7 @@ TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateThreadXPrivate) { TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateWorkerPrivateConstant) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr workerDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::threadYDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -746,6 +751,7 @@ TEST_F(OpenACCUtilsCGTest, TEST_F(OpenACCUtilsCGTest, isPrivateLocalSharedMemoryCandidateWorkerPrivateDynamicFails) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr workerDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::threadYDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); @@ -777,6 +783,7 @@ TEST_F(OpenACCUtilsCGTest, TEST_F(OpenACCUtilsCGTest, getPrivateLocalSharedMemoryUpperBoundBytes) { OwningOpRef module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); GPUParallelDimsAttr gangDims = GPUParallelDimsAttr::get( &context, {GPUParallelDimAttr::blockXDim(&context)}); auto c1 = arith::ConstantIndexOp::create(b, loc, 1); diff --git a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp index 49090f4d657d..e7ee0655d41f 100644 --- a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp +++ b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsGPUTest.cpp @@ -27,9 +27,15 @@ protected: context.loadDialect(); } + void SetUp() override { + module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); + } + MLIRContext context; OpBuilder b; Location loc; + OwningOpRef module; }; //===----------------------------------------------------------------------===// diff --git a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsReductionTest.cpp b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsReductionTest.cpp index 566f905ff24d..690b174b5ba0 100644 --- a/mlir/unittests/Dialect/OpenACC/OpenACCUtilsReductionTest.cpp +++ b/mlir/unittests/Dialect/OpenACC/OpenACCUtilsReductionTest.cpp @@ -32,9 +32,15 @@ protected: complex::ComplexDialect, memref::MemRefDialect>(); } + void SetUp() override { + module = ModuleOp::create(b, loc); + b.setInsertionPointToStart(module->getBody()); + } + MLIRContext context; OpBuilder b; Location loc; + OwningOpRef module; }; //===----------------------------------------------------------------------===//