[llvm] [SystemZ][z/OS] Fix build errors on z/OS in the Unix .inc files (PR #74758)

Abhina Sree via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 12:38:50 PST 2023


https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/74758

>From d639111183e8bfa94d694101b75648a02ad44e1d Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 7 Dec 2023 15:33:38 -0500
Subject: [PATCH 1/2] Fix build errors on z/OS in the Unix .inc files

---
 llvm/lib/Support/Unix/Process.inc |  4 ++++
 llvm/lib/Support/Unix/Program.inc | 15 +++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 2babf07944bf7..bf781eabf5c60 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -62,7 +62,9 @@ getRUsageTimes() {
   ::getrusage(RUSAGE_SELF, &RU);
   return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)};
 #else
+#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
 #warning Cannot get usage times on this platform
+#endif
   return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()};
 #endif
 }
@@ -117,7 +119,9 @@ size_t Process::GetMallocUsage() {
     return EndOfMemory - StartOfMemory;
   return 0;
 #else
+#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
 #warning Cannot get malloc info on this platform
+#endif
   return 0;
 #endif
 }
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index 9466d0f0ba859..f5881003a43bc 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -342,7 +342,7 @@ namespace sys {
 
 #if defined(_AIX)
 static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage);
-#elif !defined(__Fuchsia__)
+#elif !defined(__Fuchsia__) && !defined(__MVS__)
 using ::wait4;
 #endif
 
@@ -420,7 +420,14 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     ProcStat->reset();
 
   do {
+#ifdef __MVS__
+    WaitResult.Pid = waitpid(ChildPid, &status, WaitPidOptions);
+    int GetrusageRC = getrusage(RUSAGE_CHILDREN, &Info);
+    assert(!GetrusageRC &&
+           "Must have valid measure of the resources!");
+#else
     WaitResult.Pid = sys::wait4(ChildPid, &status, WaitPidOptions, &Info);
+#endif
   } while (WaitUntilTerminates && WaitResult.Pid == -1 && errno == EINTR);
 #endif
 
@@ -466,7 +473,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     std::chrono::microseconds UserT = toDuration(Info.ru_utime);
     std::chrono::microseconds KernelT = toDuration(Info.ru_stime);
     uint64_t PeakMemory = 0;
-#ifndef __HAIKU__
+#if !defined(__HAIKU__) && !defined(__MVS__)
     PeakMemory = static_cast<uint64_t>(Info.ru_maxrss);
 #endif
     *ProcStat = ProcessStatistics{UserT + KernelT, UserT, PeakMemory};
@@ -494,7 +501,11 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
     }
   } else if (WIFSIGNALED(status)) {
     if (ErrMsg) {
+#ifdef __MVS__
+      *ErrMsg = "Signal " + std::to_string(WTERMSIG(status));
+#else
       *ErrMsg = strsignal(WTERMSIG(status));
+#endif
 #ifdef WCOREDUMP
       if (WCOREDUMP(status))
         *ErrMsg += " (core dumped)";

>From 23ff8782c753b9c5157b47b1436de7db6c93ee8f Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Thu, 7 Dec 2023 15:38:40 -0500
Subject: [PATCH 2/2] fix formatting

---
 llvm/lib/Support/Unix/Process.inc | 4 ++--
 llvm/lib/Support/Unix/Program.inc | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index bf781eabf5c60..551f0d7f0f029 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -62,7 +62,7 @@ getRUsageTimes() {
   ::getrusage(RUSAGE_SELF, &RU);
   return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)};
 #else
-#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
+#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
 #warning Cannot get usage times on this platform
 #endif
   return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()};
@@ -119,7 +119,7 @@ size_t Process::GetMallocUsage() {
     return EndOfMemory - StartOfMemory;
   return 0;
 #else
-#ifndef __MVS__  // Exclude for MVS in case -pedantic is used
+#ifndef __MVS__ // Exclude for MVS in case -pedantic is used
 #warning Cannot get malloc info on this platform
 #endif
   return 0;
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index f5881003a43bc..fcfeafb2259c7 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -423,8 +423,7 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
 #ifdef __MVS__
     WaitResult.Pid = waitpid(ChildPid, &status, WaitPidOptions);
     int GetrusageRC = getrusage(RUSAGE_CHILDREN, &Info);
-    assert(!GetrusageRC &&
-           "Must have valid measure of the resources!");
+    assert(!GetrusageRC && "Must have valid measure of the resources!");
 #else
     WaitResult.Pid = sys::wait4(ChildPid, &status, WaitPidOptions, &Info);
 #endif



More information about the llvm-commits mailing list