Skip to content

Fixed string memory leak#2207

Merged
Mr-Anyone merged 7 commits intodevelopfrom
pr-string-leak
Jan 28, 2026
Merged

Fixed string memory leak#2207
Mr-Anyone merged 7 commits intodevelopfrom
pr-string-leak

Conversation

@Mr-Anyone
Copy link
Copy Markdown
Contributor

@Mr-Anyone Mr-Anyone commented Jan 16, 2026

Motivation

Prevent memory leak and hard to debug situations.

Technical Details

Fix memory leak making a container like llvm::SmallVector take ownership.

Resolve https://github.com/ROCm/rocMLIR-internal/issues/1987

Test Plan

Builds locally and wait for CI.

Test Result

Build locally.

Submission Checklist

@Mr-Anyone Mr-Anyone requested a review from causten as a code owner January 16, 2026 19:47
@Mr-Anyone Mr-Anyone marked this pull request as draft January 16, 2026 19:49
@Mr-Anyone
Copy link
Copy Markdown
Contributor Author

I'll try to find more of these type of issue running grep in the codebase with SmallString.

@Mr-Anyone
Copy link
Copy Markdown
Contributor Author

Also, it seems that defineDim makes a copy of llvm::StringRef as well.

void TransformMapBuilder::defineDim(StringRef name, uint32_t dim,
int64_t size) {
assert(!frozen && "It's a bug to add to a coordinate transform after "
"fetching the attribute");
bool nameInsertResult = endIndices.insert({name, dim}).second;
assert(nameInsertResult &&
"Trying to redefine a result name in a coordinate transform");
SmallString<8> nameCopy = name;
bool dimInsertResult = endNames.insert({dim, nameCopy}).second;
assert(dimInsertResult &&
"Trying to redefine a result dimension in a coordinate transform");
for (uint32_t e = endShape.size(); e <= dim; ++e) {
endShape.push_back(0);
}
endShape[dim] = size;
}

@Mr-Anyone Mr-Anyone marked this pull request as ready for review January 19, 2026 16:30
@justinrosner
Copy link
Copy Markdown
Contributor

I'll try to find more of these type of issue running grep in the codebase with SmallString.

I think you'd want to grep for uses of addDim, and other TransformMapUtils like it that take in a string, instead of just looking for SmallString.

Comment thread mlir/lib/Dialect/Rock/utility/transformMapUtils.cpp
@dhernandez0
Copy link
Copy Markdown
Contributor

it can be a separate PR, but it'd be nice to change TransformMapBuilder and subclasses to not take "StringRef" to avoid these kind of issues.

@Mr-Anyone
Copy link
Copy Markdown
Contributor Author

I have grep the following and made the changes:

\.passThrough\(
\.constDim\(
\.embed\(
\.unmerge\(
\.merge\(
\.takeRemainder\(
\.addDim\(
\.dropDimAtIndex\(
\.dropDimsAtIndices\(
\.slice\(

@justinrosner
Copy link
Copy Markdown
Contributor

it can be a separate PR, but it'd be nice to change TransformMapBuilder and subclasses to not take "StringRef" to avoid these kind of issues.

@Mr-Anyone Can you make sure that we have a ticket open in our backlog to properly addresses changing the API for these transform map function?

@Mr-Anyone Mr-Anyone merged commit 6417b22 into develop Jan 28, 2026
9 of 16 checks passed
@Mr-Anyone Mr-Anyone deleted the pr-string-leak branch January 28, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants