[flang-commits] [flang] [flang] Fix const cast issue in FreeMemory function call in execute_command_line (PR #77906)

via flang-commits flang-commits at lists.llvm.org
Fri Jan 12 03:05:29 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-runtime

Author: Yi Wu (yi-wu-arm)

<details>
<summary>Changes</summary>

The FreeMemory function only accepts a void pointer, but it was being called with a const char pointer, resulting in a type-casting issue.
To address this, the commit replaces the direct cast with a const_cast<void *>(static_cast<const void *>(newCmd).

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


1 Files Affected:

- (modified) flang/runtime/execute.cpp (+1-1) 


``````````diff
diff --git a/flang/runtime/execute.cpp b/flang/runtime/execute.cpp
index 48773ae8114b0b..fa2b7eca0dde69 100644
--- a/flang/runtime/execute.cpp
+++ b/flang/runtime/execute.cpp
@@ -199,7 +199,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
   }
   // Deallocate memory if EnsureNullTerminated dynamically allocated memory
   if (newCmd != command.OffsetElement()) {
-    FreeMemory((void *)newCmd);
+    FreeMemory(const_cast<void *>(static_cast<const void *>(newCmd)));
   }
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/77906


More information about the flang-commits mailing list