https://github.com/maryammo updated 
https://github.com/llvm/llvm-project/pull/204472

>From 843c95b8abf380f098ede9995b472fa735550ce4 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <[email protected]>
Date: Wed, 17 Jun 2026 18:45:03 +0000
Subject: [PATCH 1/2] [z/OS][Clang] Add wrapper headers to avoid macro name
 conflicts

---
 clang/lib/Headers/CMakeLists.txt              |  8 +++++
 clang/lib/Headers/zos_wrappers/grp.h          | 19 ++++++++++++
 clang/lib/Headers/zos_wrappers/locale.h       | 19 ++++++++++++
 clang/lib/Headers/zos_wrappers/math.h         | 31 +++++++++++++++++++
 clang/lib/Headers/zos_wrappers/poll.h         | 19 ++++++++++++
 clang/lib/Headers/zos_wrappers/stdlib.h       | 20 ++++++++++++
 clang/lib/Headers/zos_wrappers/string.h       | 19 ++++++++++++
 clang/lib/Headers/zos_wrappers/time.h         | 19 ++++++++++++
 clang/lib/Headers/zos_wrappers/variant.h      | 19 ++++++++++++
 .../test/Headers/Inputs/zos/usr/include/grp.h |  1 +
 .../Headers/Inputs/zos/usr/include/locale.h   |  1 +
 .../Headers/Inputs/zos/usr/include/math.h     |  2 ++
 .../Headers/Inputs/zos/usr/include/poll.h     |  1 +
 .../Headers/Inputs/zos/usr/include/stdlib.h   |  1 +
 .../Headers/Inputs/zos/usr/include/string.h   |  1 +
 .../Headers/Inputs/zos/usr/include/time.h     |  1 +
 .../Headers/Inputs/zos/usr/include/variant.h  |  1 +
 clang/test/Headers/zos-guard.c                | 19 ++++++++++++
 18 files changed, 201 insertions(+)
 create mode 100644 clang/lib/Headers/zos_wrappers/grp.h
 create mode 100644 clang/lib/Headers/zos_wrappers/locale.h
 create mode 100644 clang/lib/Headers/zos_wrappers/math.h
 create mode 100644 clang/lib/Headers/zos_wrappers/poll.h
 create mode 100644 clang/lib/Headers/zos_wrappers/stdlib.h
 create mode 100644 clang/lib/Headers/zos_wrappers/string.h
 create mode 100644 clang/lib/Headers/zos_wrappers/time.h
 create mode 100644 clang/lib/Headers/zos_wrappers/variant.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/grp.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/locale.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/math.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/poll.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/stdlib.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/string.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/time.h
 create mode 100644 clang/test/Headers/Inputs/zos/usr/include/variant.h
 create mode 100644 clang/test/Headers/zos-guard.c

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 439f2725168ba..5201bf8e4770c 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -407,6 +407,14 @@ set(llvm_libc_wrapper_files
 
 set(zos_wrapper_files
   zos_wrappers/builtins.h
+  zos_wrappers/grp.h
+  zos_wrappers/locale.h
+  zos_wrappers/math.h
+  zos_wrappers/poll.h
+  zos_wrappers/stdlib.h
+  zos_wrappers/string.h
+  zos_wrappers/time.h
+  zos_wrappers/variant.h
 )
 
 include(GetClangResourceDir)
diff --git a/clang/lib/Headers/zos_wrappers/grp.h 
b/clang/lib/Headers/zos_wrappers/grp.h
new file mode 100644
index 0000000000000..854df2337ba76
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/grp.h
@@ -0,0 +1,19 @@
+/*===----------------------------- grp.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_GRP_H
+#define __ZOS_WRAPPERS_GRP_H
+#if defined(__MVS__)
+#include_next <grp.h>
+#ifdef __grp
+#undef __grp
+#define __grp __grp
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_GRP_H */
diff --git a/clang/lib/Headers/zos_wrappers/locale.h 
b/clang/lib/Headers/zos_wrappers/locale.h
new file mode 100644
index 0000000000000..456be8df385c6
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/locale.h
@@ -0,0 +1,19 @@
+/*===----------------------------- locale.h 
---------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_LOCALE_H
+#define __ZOS_WRAPPERS_LOCALE_H
+#if defined(__MVS__)
+#include_next <locale.h>
+#ifdef __locale
+#undef __locale
+#define __locale __locale
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_LOCALE_H */
diff --git a/clang/lib/Headers/zos_wrappers/math.h 
b/clang/lib/Headers/zos_wrappers/math.h
new file mode 100644
index 0000000000000..8b24ef15a5481
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/math.h
@@ -0,0 +1,31 @@
+/*===----------------------------- math.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_MATH_H
+#define __ZOS_WRAPPERS_MATH_H
+#if defined(__MVS__)
+#include_next <math.h>
+#ifdef __math
+#undef __math
+#define __math __math
+#endif
+#ifndef __BFP__
+#ifdef __cplusplus
+extern "C"
+#endif
+    double fabs(double x) __THROW;
+#endif
+#if !defined(__LP64__) && !defined(__BFP__)
+#ifdef __C99
+#pragma map(tgammaf, "\174\174TGMFH9")
+#pragma map(tgamma, "\174\174TGMAH9")
+#endif
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_MATH_H */
diff --git a/clang/lib/Headers/zos_wrappers/poll.h 
b/clang/lib/Headers/zos_wrappers/poll.h
new file mode 100644
index 0000000000000..4c753e14dfc1e
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/poll.h
@@ -0,0 +1,19 @@
+/*===----------------------------- poll.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_POLL_H
+#define __ZOS_WRAPPERS_POLL_H
+#if defined(__MVS__)
+#include_next <poll.h>
+#ifdef __poll
+#undef __poll
+#define __poll __poll
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_POLL_H */
diff --git a/clang/lib/Headers/zos_wrappers/stdlib.h 
b/clang/lib/Headers/zos_wrappers/stdlib.h
new file mode 100644
index 0000000000000..95fdec8e1fbbd
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/stdlib.h
@@ -0,0 +1,20 @@
+/*===----------------------------- stdlib.h --------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_STDLIB_H
+#define __ZOS_WRAPPERS_STDLIB_H
+#if defined(__MVS__)
+#include_next <stdlib.h>
+#ifdef _EXT
+#ifndef __CS1
+#undef __cs
+#endif
+#endif /* _EXT */
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_STDLIB_H */
diff --git a/clang/lib/Headers/zos_wrappers/string.h 
b/clang/lib/Headers/zos_wrappers/string.h
new file mode 100644
index 0000000000000..4b48612994f69
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/string.h
@@ -0,0 +1,19 @@
+/*===--------------------------- string.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_STRING_H
+#define __ZOS_WRAPPERS_STRING_H
+#if defined(__MVS__)
+#include_next <string.h>
+#ifdef __string
+#undef __string
+#define __string __string
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_STRING_H */
diff --git a/clang/lib/Headers/zos_wrappers/time.h 
b/clang/lib/Headers/zos_wrappers/time.h
new file mode 100644
index 0000000000000..74cf158c9df55
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/time.h
@@ -0,0 +1,19 @@
+/*===----------------------------- time.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_TIME_H
+#define __ZOS_WRAPPERS_TIME_H
+#if defined(__MVS__)
+#include_next <time.h>
+#ifdef __time
+#undef __time
+#define __time __time
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_TIME_H */
diff --git a/clang/lib/Headers/zos_wrappers/variant.h 
b/clang/lib/Headers/zos_wrappers/variant.h
new file mode 100644
index 0000000000000..7f46ec96929c3
--- /dev/null
+++ b/clang/lib/Headers/zos_wrappers/variant.h
@@ -0,0 +1,19 @@
+/*===-------------------------- variant.h ----------------------------------===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __ZOS_WRAPPERS_VARIANT_H
+#define __ZOS_WRAPPERS_VARIANT_H
+#if defined(__MVS__)
+#include_next <variant.h>
+#ifdef __variant
+#undef __variant
+#define __variant __variant
+#endif
+#endif /* defined(__MVS__) */
+#endif /* __ZOS_WRAPPERS_VARIANT_H */
diff --git a/clang/test/Headers/Inputs/zos/usr/include/grp.h 
b/clang/test/Headers/Inputs/zos/usr/include/grp.h
new file mode 100644
index 0000000000000..1c6baae11c74f
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/grp.h
@@ -0,0 +1 @@
+#define __grp 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/locale.h 
b/clang/test/Headers/Inputs/zos/usr/include/locale.h
new file mode 100644
index 0000000000000..8e27d077fb9f8
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/locale.h
@@ -0,0 +1 @@
+#define __locale 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/math.h 
b/clang/test/Headers/Inputs/zos/usr/include/math.h
new file mode 100644
index 0000000000000..6eb5879bf48c6
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/math.h
@@ -0,0 +1,2 @@
+#define __math 1
+#define __THROW
diff --git a/clang/test/Headers/Inputs/zos/usr/include/poll.h 
b/clang/test/Headers/Inputs/zos/usr/include/poll.h
new file mode 100644
index 0000000000000..7ec0d68cc617d
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/poll.h
@@ -0,0 +1 @@
+#define __poll 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/stdlib.h 
b/clang/test/Headers/Inputs/zos/usr/include/stdlib.h
new file mode 100644
index 0000000000000..d3b8b1eda0752
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/stdlib.h
@@ -0,0 +1 @@
+#define __cs 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/string.h 
b/clang/test/Headers/Inputs/zos/usr/include/string.h
new file mode 100644
index 0000000000000..487402b00bfde
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/string.h
@@ -0,0 +1 @@
+#define __string 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/time.h 
b/clang/test/Headers/Inputs/zos/usr/include/time.h
new file mode 100644
index 0000000000000..6639ec4be0964
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/time.h
@@ -0,0 +1 @@
+#define __time 1
diff --git a/clang/test/Headers/Inputs/zos/usr/include/variant.h 
b/clang/test/Headers/Inputs/zos/usr/include/variant.h
new file mode 100644
index 0000000000000..45550cd89023b
--- /dev/null
+++ b/clang/test/Headers/Inputs/zos/usr/include/variant.h
@@ -0,0 +1 @@
+#define __variant 1
diff --git a/clang/test/Headers/zos-guard.c b/clang/test/Headers/zos-guard.c
new file mode 100644
index 0000000000000..2ca4956ba21dc
--- /dev/null
+++ b/clang/test/Headers/zos-guard.c
@@ -0,0 +1,19 @@
+//RUN: %clang -c  --target=s390x-ibm-zos %s 
-mzos-sys-include=%S/Inputs/zos/usr/include -Xclang -verify
+
+// expected-no-diagnostics
+
+#include <grp.h>
+#include <locale.h>
+#include <math.h>
+#include <poll.h>
+#include <string.h>
+#include <time.h>
+#include <variant.h>
+
+int __grp;
+int __locale;
+int __math;
+int __poll;
+int __string;
+int __time;
+int __variant;

>From 911f241001c760580ab75f4266e01ca6c9295224 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <[email protected]>
Date: Thu, 25 Jun 2026 15:13:08 +0000
Subject: [PATCH 2/2] Use header availability checks instead of platform macro

---
 clang/lib/Headers/zos_wrappers/grp.h     | 4 ++--
 clang/lib/Headers/zos_wrappers/locale.h  | 4 ++--
 clang/lib/Headers/zos_wrappers/math.h    | 4 ++--
 clang/lib/Headers/zos_wrappers/poll.h    | 4 ++--
 clang/lib/Headers/zos_wrappers/stdlib.h  | 4 ++--
 clang/lib/Headers/zos_wrappers/string.h  | 4 ++--
 clang/lib/Headers/zos_wrappers/time.h    | 4 ++--
 clang/lib/Headers/zos_wrappers/variant.h | 4 ++--
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Headers/zos_wrappers/grp.h 
b/clang/lib/Headers/zos_wrappers/grp.h
index 854df2337ba76..8a508493a1835 100644
--- a/clang/lib/Headers/zos_wrappers/grp.h
+++ b/clang/lib/Headers/zos_wrappers/grp.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_GRP_H
 #define __ZOS_WRAPPERS_GRP_H
-#if defined(__MVS__)
+#if __has_include_next(<grp.h>)
 #include_next <grp.h>
 #ifdef __grp
 #undef __grp
 #define __grp __grp
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<grp.h>) */
 #endif /* __ZOS_WRAPPERS_GRP_H */
diff --git a/clang/lib/Headers/zos_wrappers/locale.h 
b/clang/lib/Headers/zos_wrappers/locale.h
index 456be8df385c6..eb888f4b11490 100644
--- a/clang/lib/Headers/zos_wrappers/locale.h
+++ b/clang/lib/Headers/zos_wrappers/locale.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_LOCALE_H
 #define __ZOS_WRAPPERS_LOCALE_H
-#if defined(__MVS__)
+#if __has_include_next(<locale.h>)
 #include_next <locale.h>
 #ifdef __locale
 #undef __locale
 #define __locale __locale
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<locale.h>) */
 #endif /* __ZOS_WRAPPERS_LOCALE_H */
diff --git a/clang/lib/Headers/zos_wrappers/math.h 
b/clang/lib/Headers/zos_wrappers/math.h
index 8b24ef15a5481..09ee5af81a03a 100644
--- a/clang/lib/Headers/zos_wrappers/math.h
+++ b/clang/lib/Headers/zos_wrappers/math.h
@@ -9,7 +9,7 @@
 
 #ifndef __ZOS_WRAPPERS_MATH_H
 #define __ZOS_WRAPPERS_MATH_H
-#if defined(__MVS__)
+#if __has_include_next(<math.h>)
 #include_next <math.h>
 #ifdef __math
 #undef __math
@@ -27,5 +27,5 @@ extern "C"
 #pragma map(tgamma, "\174\174TGMAH9")
 #endif
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<math.h>) */
 #endif /* __ZOS_WRAPPERS_MATH_H */
diff --git a/clang/lib/Headers/zos_wrappers/poll.h 
b/clang/lib/Headers/zos_wrappers/poll.h
index 4c753e14dfc1e..98c12d555686a 100644
--- a/clang/lib/Headers/zos_wrappers/poll.h
+++ b/clang/lib/Headers/zos_wrappers/poll.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_POLL_H
 #define __ZOS_WRAPPERS_POLL_H
-#if defined(__MVS__)
+#if __has_include_next(<poll.h>)
 #include_next <poll.h>
 #ifdef __poll
 #undef __poll
 #define __poll __poll
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<poll.h>) */
 #endif /* __ZOS_WRAPPERS_POLL_H */
diff --git a/clang/lib/Headers/zos_wrappers/stdlib.h 
b/clang/lib/Headers/zos_wrappers/stdlib.h
index 95fdec8e1fbbd..433e1b5ad0b23 100644
--- a/clang/lib/Headers/zos_wrappers/stdlib.h
+++ b/clang/lib/Headers/zos_wrappers/stdlib.h
@@ -9,12 +9,12 @@
 
 #ifndef __ZOS_WRAPPERS_STDLIB_H
 #define __ZOS_WRAPPERS_STDLIB_H
-#if defined(__MVS__)
+#if __has_include_next(<stdlib.h>)
 #include_next <stdlib.h>
 #ifdef _EXT
 #ifndef __CS1
 #undef __cs
 #endif
 #endif /* _EXT */
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<stdlib.h>) */
 #endif /* __ZOS_WRAPPERS_STDLIB_H */
diff --git a/clang/lib/Headers/zos_wrappers/string.h 
b/clang/lib/Headers/zos_wrappers/string.h
index 4b48612994f69..868e40f5bd143 100644
--- a/clang/lib/Headers/zos_wrappers/string.h
+++ b/clang/lib/Headers/zos_wrappers/string.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_STRING_H
 #define __ZOS_WRAPPERS_STRING_H
-#if defined(__MVS__)
+#if __has_include_next(<string.h>)
 #include_next <string.h>
 #ifdef __string
 #undef __string
 #define __string __string
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<string.h>) */
 #endif /* __ZOS_WRAPPERS_STRING_H */
diff --git a/clang/lib/Headers/zos_wrappers/time.h 
b/clang/lib/Headers/zos_wrappers/time.h
index 74cf158c9df55..164af3441549b 100644
--- a/clang/lib/Headers/zos_wrappers/time.h
+++ b/clang/lib/Headers/zos_wrappers/time.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_TIME_H
 #define __ZOS_WRAPPERS_TIME_H
-#if defined(__MVS__)
+#if __has_include_next(<time.h>)
 #include_next <time.h>
 #ifdef __time
 #undef __time
 #define __time __time
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<time.h>) */
 #endif /* __ZOS_WRAPPERS_TIME_H */
diff --git a/clang/lib/Headers/zos_wrappers/variant.h 
b/clang/lib/Headers/zos_wrappers/variant.h
index 7f46ec96929c3..41ae50ff19566 100644
--- a/clang/lib/Headers/zos_wrappers/variant.h
+++ b/clang/lib/Headers/zos_wrappers/variant.h
@@ -9,11 +9,11 @@
 
 #ifndef __ZOS_WRAPPERS_VARIANT_H
 #define __ZOS_WRAPPERS_VARIANT_H
-#if defined(__MVS__)
+#if __has_include_next(<variant.h>)
 #include_next <variant.h>
 #ifdef __variant
 #undef __variant
 #define __variant __variant
 #endif
-#endif /* defined(__MVS__) */
+#endif /* __has_include_next(<variant.h>) */
 #endif /* __ZOS_WRAPPERS_VARIANT_H */

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to