Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][AsmParser] Avoid use of moved value #108789

Merged
merged 1 commit into from
Sep 16, 2024
Merged

Conversation

JOE1994
Copy link
Member

@JOE1994 JOE1994 commented Sep 16, 2024

'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.

'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.
@JOE1994 JOE1994 requested a review from River707 September 16, 2024 04:13
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Sep 16, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Youngsuk Kim (JOE1994)

Changes

'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.


Full diff: https://github.com/llvm/llvm-project/pull/108789.diff

1 Files Affected:

  • (modified) mlir/lib/AsmParser/Parser.cpp (+4-3)
diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp
index 2e4c4a36d46b9b..83eec3244009d8 100644
--- a/mlir/lib/AsmParser/Parser.cpp
+++ b/mlir/lib/AsmParser/Parser.cpp
@@ -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)) {
@@ -2440,7 +2441,7 @@ ParseResult OperationParser::codeCompleteSSAUse() {
         detailOS << ", ...";
 
       state.codeCompleteContext->appendSSAValueCompletion(
-          it.getKey(), std::move(detailOS.str()));
+          it.getKey(), std::move(detailData));
     }
   }
 

@JOE1994 JOE1994 merged commit cab4c10 into llvm:main Sep 16, 2024
11 checks passed
@JOE1994 JOE1994 deleted the mlir_fix branch September 16, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants