Skip to content

Commit

Permalink
[mlir][AsmParser] Avoid use of moved value (#108789)
Browse files Browse the repository at this point in the history
'std::string detailData' is moved in the innermost loop of a 2-layer
loop, but is written to throughout the whole duration of the 2-layer
loop.

After move, std::string is in an unspecified state
(implementation-dependent).

Avoid using a moved value, as it incurs undefined behavior.
  • Loading branch information
JOE1994 authored Sep 16, 2024
1 parent 6784202 commit cab4c10
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mlir/lib/AsmParser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,14 +2412,15 @@ ParseResult OperationParser::parseOptionalBlockArgList(Block *owner) {
//===----------------------------------------------------------------------===//

ParseResult OperationParser::codeCompleteSSAUse() {
std::string detailData;
llvm::raw_string_ostream detailOS(detailData);
for (IsolatedSSANameScope &scope : isolatedNameScopes) {
for (auto &it : scope.values) {
if (it.second.empty())
continue;
Value frontValue = it.second.front().value;

std::string detailData;
llvm::raw_string_ostream detailOS(detailData);

// If the value isn't a forward reference, we also add the name of the op
// to the detail.
if (auto result = dyn_cast<OpResult>(frontValue)) {
Expand All @@ -2440,7 +2441,7 @@ ParseResult OperationParser::codeCompleteSSAUse() {
detailOS << ", ...";

state.codeCompleteContext->appendSSAValueCompletion(
it.getKey(), std::move(detailOS.str()));
it.getKey(), std::move(detailData));
}
}

Expand Down

0 comments on commit cab4c10

Please sign in to comment.