[flang] [llvm] [flang] Add runtime and lowering implementation for extended intrinsic PUTENV (PR #134412)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 09:40:31 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- flang-rt/include/flang-rt/runtime/environment.h flang-rt/lib/runtime/command.cpp flang-rt/lib/runtime/environment.cpp flang/include/flang/Optimizer/Builder/IntrinsicCall.h flang/include/flang/Optimizer/Builder/Runtime/Command.h flang/include/flang/Runtime/command.h flang/lib/Evaluate/intrinsics.cpp flang/lib/Optimizer/Builder/IntrinsicCall.cpp flang/lib/Optimizer/Builder/Runtime/Command.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang-rt/include/flang-rt/runtime/environment.h b/flang-rt/include/flang-rt/runtime/environment.h
index 6e496d383..16258b3bb 100644
--- a/flang-rt/include/flang-rt/runtime/environment.h
+++ b/flang-rt/include/flang-rt/runtime/environment.h
@@ -45,14 +45,12 @@ struct ExecutionEnvironment {
   const char *GetEnv(
       const char *name, std::size_t name_length, const Terminator &terminator);
 
-  std::int32_t SetEnv(
-      const char *name, std::size_t name_length,
+  std::int32_t SetEnv(const char *name, std::size_t name_length,
       const char *value, std::size_t value_length,
       const Terminator &terminator);
 
   std::int32_t UnsetEnv(
-      const char *name, std::size_t name_length,
-      const Terminator &terminator);
+      const char *name, std::size_t name_length, const Terminator &terminator);
 
   int argc{0};
   const char **argv{nullptr};
diff --git a/flang-rt/lib/runtime/command.cpp b/flang-rt/lib/runtime/command.cpp
index c0a0dbbf4..a4e8e31ad 100644
--- a/flang-rt/lib/runtime/command.cpp
+++ b/flang-rt/lib/runtime/command.cpp
@@ -339,12 +339,10 @@ std::int32_t RTNAME(PutEnv)(
   if (str_sep == str_end) {
     // No separator, invalid input string
     status = EINVAL;
-  }
-  else if ((str_sep + 1) == str_end) {
+  } else if ((str_sep + 1) == str_end) {
     // "name=" form, which means we need to delete this variable
     status = executionEnvironment.UnsetEnv(str, str_sep - str, terminator);
-  }
-  else {
+  } else {
     // Example: consider str "abc=defg", str_length = 8
     //
     // addr:     05 06 07 08 09 10 11 12 13
@@ -354,7 +352,7 @@ std::int32_t RTNAME(PutEnv)(
     // value ptr: str_sep + 1 = 9, value length: 4
     //
     status = executionEnvironment.SetEnv(
-      str, str_sep - str, str_sep + 1, str_end - str_sep - 1, terminator);
+        str, str_sep - str, str_sep + 1, str_end - str_sep - 1, terminator);
   }
 
   return status;
diff --git a/flang-rt/lib/runtime/environment.cpp b/flang-rt/lib/runtime/environment.cpp
index 1030ed615..1d5304254 100644
--- a/flang-rt/lib/runtime/environment.cpp
+++ b/flang-rt/lib/runtime/environment.cpp
@@ -182,10 +182,9 @@ const char *ExecutionEnvironment::GetEnv(
   return std::getenv(cStyleName.get());
 }
 
-std::int32_t ExecutionEnvironment::SetEnv(
-  const char *name, std::size_t name_length,
-  const char *value, std::size_t value_length,
-  const Terminator &terminator) {
+std::int32_t ExecutionEnvironment::SetEnv(const char *name,
+    std::size_t name_length, const char *value, std::size_t value_length,
+    const Terminator &terminator) {
 
   RUNTIME_CHECK(terminator, name && name_length && value && value_length);
 
@@ -210,8 +209,7 @@ std::int32_t ExecutionEnvironment::SetEnv(
 
 #endif
 
-  if (status != 0)
-  {
+  if (status != 0) {
     status = errno;
   }
 
@@ -219,8 +217,7 @@ std::int32_t ExecutionEnvironment::SetEnv(
 }
 
 std::int32_t ExecutionEnvironment::UnsetEnv(
-    const char *name, std::size_t name_length,
-    const Terminator &terminator) {
+    const char *name, std::size_t name_length, const Terminator &terminator) {
 
   RUNTIME_CHECK(terminator, name && name_length);
 
@@ -241,8 +238,7 @@ std::int32_t ExecutionEnvironment::UnsetEnv(
 
 #endif
 
-  if (status != 0)
-  {
+  if (status != 0) {
     status = errno;
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list