Author: Maryam Moghadas Date: 2026-07-03T16:03:13-04:00 New Revision: 0418a88ae67165a2f7af0e25ad34fdaa84df3b21
URL: https://github.com/llvm/llvm-project/commit/0418a88ae67165a2f7af0e25ad34fdaa84df3b21 DIFF: https://github.com/llvm/llvm-project/commit/0418a88ae67165a2f7af0e25ad34fdaa84df3b21.diff LOG: [z/OS][Clang] Reland Add wrapper headers to avoid macro name conflicts (#204472) (#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. Reland of 04079deb547c91eff6c6e2b820dbe6937c72fcf5. Add systemz-registered-target requirement to zos-guard.c. Added: clang/lib/Headers/zos_wrappers/grp.h clang/lib/Headers/zos_wrappers/locale.h clang/lib/Headers/zos_wrappers/math.h clang/lib/Headers/zos_wrappers/poll.h clang/lib/Headers/zos_wrappers/string.h clang/lib/Headers/zos_wrappers/time.h clang/lib/Headers/zos_wrappers/variant.h clang/test/Headers/Inputs/zos/usr/include/grp.h clang/test/Headers/Inputs/zos/usr/include/locale.h clang/test/Headers/Inputs/zos/usr/include/math.h clang/test/Headers/Inputs/zos/usr/include/poll.h clang/test/Headers/Inputs/zos/usr/include/string.h clang/test/Headers/Inputs/zos/usr/include/time.h clang/test/Headers/Inputs/zos/usr/include/variant.h clang/test/Headers/zos-guard.c Modified: clang/lib/Headers/CMakeLists.txt Removed: ################################################################################ diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index fc8ddb4284f31..6bc5e5ee04e0f 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -409,6 +409,13 @@ 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/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/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/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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
