Skip to content

Commit cab4c10

Browse files
authored
[mlir][AsmParser] Avoid use of moved value (#108789)
'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.
1 parent 6784202 commit cab4c10

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mlir/lib/AsmParser/Parser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,14 +2412,15 @@ ParseResult OperationParser::parseOptionalBlockArgList(Block *owner) {
24122412
//===----------------------------------------------------------------------===//
24132413

24142414
ParseResult OperationParser::codeCompleteSSAUse() {
2415-
std::string detailData;
2416-
llvm::raw_string_ostream detailOS(detailData);
24172415
for (IsolatedSSANameScope &scope : isolatedNameScopes) {
24182416
for (auto &it : scope.values) {
24192417
if (it.second.empty())
24202418
continue;
24212419
Value frontValue = it.second.front().value;
24222420

2421+
std::string detailData;
2422+
llvm::raw_string_ostream detailOS(detailData);
2423+
24232424
// If the value isn't a forward reference, we also add the name of the op
24242425
// to the detail.
24252426
if (auto result = dyn_cast<OpResult>(frontValue)) {
@@ -2440,7 +2441,7 @@ ParseResult OperationParser::codeCompleteSSAUse() {
24402441
detailOS << ", ...";
24412442

24422443
state.codeCompleteContext->appendSSAValueCompletion(
2443-
it.getKey(), std::move(detailOS.str()));
2444+
it.getKey(), std::move(detailData));
24442445
}
24452446
}
24462447

0 commit comments

Comments
 (0)