[clang] [z/OS][Clang] Reland Add wrapper headers to avoid macro name conflicts (#204472) (PR #207420)
Maryam Moghadas via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 3 08:53:10 PDT 2026
https://github.com/maryammo created https://github.com/llvm/llvm-project/pull/207420
Some z/OS system headers define macros (e.g. __time, __math) that conflict with user identifiers and break compilation. These wrappers include the system headers and neutralize the problematic macros.
>From fa8f9ccc9dcd01f96ba0e38ff380c9aa9dfb61f9 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas <maryammo at ca.ibm.com>
Date: Tue, 30 Jun 2026 12:37:51 -0400
Subject: [PATCH] [z/OS][Clang] Reland Add wrapper headers to avoid macro name
conflicts (#204472)
Some z/OS system headers define macros (e.g. __time, __math) that
conflict with user identifiers and break compilation. These wrappers include
the system headers and neutralize the problematic macros.
---
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 | 20 ++++++++++++
18 files changed, 202 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 fc8ddb4284f31..30062cd942643 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -409,6 +409,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..8a508493a1835
--- /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 __has_include_next(<grp.h>)
+#include_next <grp.h>
+#ifdef __grp
+#undef __grp
+#define __grp __grp
+#endif
+#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
new file mode 100644
index 0000000000000..eb888f4b11490
--- /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 __has_include_next(<locale.h>)
+#include_next <locale.h>
+#ifdef __locale
+#undef __locale
+#define __locale __locale
+#endif
+#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
new file mode 100644
index 0000000000000..09ee5af81a03a
--- /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 __has_include_next(<math.h>)
+#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 /* __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
new file mode 100644
index 0000000000000..98c12d555686a
--- /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 __has_include_next(<poll.h>)
+#include_next <poll.h>
+#ifdef __poll
+#undef __poll
+#define __poll __poll
+#endif
+#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
new file mode 100644
index 0000000000000..433e1b5ad0b23
--- /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 __has_include_next(<stdlib.h>)
+#include_next <stdlib.h>
+#ifdef _EXT
+#ifndef __CS1
+#undef __cs
+#endif
+#endif /* _EXT */
+#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
new file mode 100644
index 0000000000000..868e40f5bd143
--- /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 __has_include_next(<string.h>)
+#include_next <string.h>
+#ifdef __string
+#undef __string
+#define __string __string
+#endif
+#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
new file mode 100644
index 0000000000000..164af3441549b
--- /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 __has_include_next(<time.h>)
+#include_next <time.h>
+#ifdef __time
+#undef __time
+#define __time __time
+#endif
+#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
new file mode 100644
index 0000000000000..41ae50ff19566
--- /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 __has_include_next(<variant.h>)
+#include_next <variant.h>
+#ifdef __variant
+#undef __variant
+#define __variant __variant
+#endif
+#endif /* __has_include_next(<variant.h>) */
+#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..e959f559284b6
--- /dev/null
+++ b/clang/test/Headers/zos-guard.c
@@ -0,0 +1,20 @@
+// REQUIRES: systemz-registered-target
+//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;
More information about the cfe-commits
mailing list