[clang] [z/OS][Clang] Add wrapper headers to avoid macro name conflicts (PR #204472)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 17 14:52:08 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Maryam Moghadas (maryammo)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/204472.diff
18 Files Affected:
- (modified) clang/lib/Headers/CMakeLists.txt (+8)
- (added) clang/lib/Headers/zos_wrappers/grp.h (+19)
- (added) clang/lib/Headers/zos_wrappers/locale.h (+19)
- (added) clang/lib/Headers/zos_wrappers/math.h (+31)
- (added) clang/lib/Headers/zos_wrappers/poll.h (+19)
- (added) clang/lib/Headers/zos_wrappers/stdlib.h (+20)
- (added) clang/lib/Headers/zos_wrappers/string.h (+19)
- (added) clang/lib/Headers/zos_wrappers/time.h (+19)
- (added) clang/lib/Headers/zos_wrappers/variant.h (+19)
- (added) clang/test/Headers/Inputs/zos/usr/include/grp.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/locale.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/math.h (+2)
- (added) clang/test/Headers/Inputs/zos/usr/include/poll.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/stdlib.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/string.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/time.h (+1)
- (added) clang/test/Headers/Inputs/zos/usr/include/variant.h (+1)
- (added) clang/test/Headers/zos-guard.c (+19)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/204472
More information about the cfe-commits
mailing list