[TEST] Add ASan/LeakSanitizer harness and fix memory bugs it found - #7831
Open
Niz13 wants to merge 1 commit into
Open
[TEST] Add ASan/LeakSanitizer harness and fix memory bugs it found#7831Niz13 wants to merge 1 commit into
Niz13 wants to merge 1 commit into
Conversation
Implements the host-side memory-leak check requested in issue #5029. - scripts/test-triton.sh gains `--asan`: runs the host-side ctest and lit suites under LeakSanitizer. Sets allow_user_poisoning=0 to neutralize the false use-after-poison from linking instrumented Triton against the non-instrumented prebuilt LLVM, guards that triton-opt is ASan-instrumented, and wires in the suppressions file. - scripts/asan/lsan.supp suppresses only benign LLVM/MLIR globals (never anything under third_party/intel). Fixes found by the harness: - StrideVersioning erased a loop from inside a pre-order walk(), so the walker dereferenced the freed op (heap-use-after-free). Switch to collect-then-mutate: gather candidate loops during the walk, version them afterwards. - Six Analysis unit-test fixtures returned a raw ModuleOp from ModuleOp::create() and never freed it. Own each module in a SmallVector<OwningOpRef<ModuleOp>> member declared after the MLIRContext. Host-side ctest (453) and lit (446) run clean under LeakSanitizer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
anmyachev
reviewed
Aug 24, 2026
| // ModuleOp::create() are owned by nothing, so without this they leak (caught | ||
| // by LeakSanitizer). Declared after `ctx` so the modules are erased before | ||
| // the context is destroyed. | ||
| SmallVector<OwningOpRef<ModuleOp>> modules; |
Contributor
There was a problem hiding this comment.
Can we just change methods/functions signature to return OwningOpRef<ModuleOp> (like in lib\Dialect\TritonGPU\Transforms\WarpSpecialization\OptimizePartitionWarps.cpp) and avoid using separate variables to manage ModuleOp's lifecycle?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the host-side memory-leak check requested in #5029.
Harness
scripts/test-triton.sh --asanruns the host-side C++ (ctest) and MLIRlitsuites under LeakSanitizer. SetsASAN_OPTIONS=allow_user_poisoning=0to neutralize a false use-after-poison caused by linking ASan-instrumented Triton against the non-instrumented prebuilt LLVM (does not weaken leak/redzone detection), and guards thattriton-optis actually ASan-instrumented.scripts/asan/lsan.suppsuppresses only benign LLVM/MLIR globals — nothing underthird_party/intel.Bugs found & fixed
StrideVersioning— the pass calledforOp.erase()inside a pre-orderwalk(), so the walker then dereferenced the freed op. Fixed with collect-then-mutate: gather candidate loops during the walk, version them afterwards (safe — only non-nested top-level loops are candidates).ModuleOpleaks inAnalysisunit-test fixtures —ModuleOp::create()returned raw and was never freed. Fixed by owning modules in aSmallVector<OwningOpRef<ModuleOp>>member declared after theMLIRContext.Result (under LeakSanitizer)
ctestlit🤖 Generated with Claude Code