Skip to content

[z/OS] add support for z/OS system headers to clang std header wrappers #89995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ set(llvm_libc_wrapper_files
llvm_libc_wrappers/time.h
)

set(zos_wrapper_files
zos_wrappers/builtins.h
)

include(GetClangResourceDir)
get_clang_resource_dir(output_dir PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
set(out_files)
Expand Down Expand Up @@ -370,7 +374,7 @@ endfunction(clang_generate_header)

# Copy header files from the source directory to the build directory
foreach( f ${files} ${cuda_wrapper_files} ${cuda_wrapper_bits_files}
${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files}
${ppc_wrapper_files} ${openmp_wrapper_files} ${zos_wrapper_files} ${hlsl_files}
${llvm_libc_wrapper_files})
copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
endforeach( f )
Expand Down Expand Up @@ -487,7 +491,7 @@ add_header_target("mips-resource-headers" "${mips_msa_files}")
add_header_target("ppc-resource-headers" "${ppc_files};${ppc_wrapper_files}")
add_header_target("ppc-htm-resource-headers" "${ppc_htm_files}")
add_header_target("riscv-resource-headers" "${riscv_files};${riscv_generated_files}")
add_header_target("systemz-resource-headers" "${systemz_files}")
add_header_target("systemz-resource-headers" "${systemz_files};${zos_wrapper_files}")
add_header_target("ve-resource-headers" "${ve_files}")
add_header_target("webassembly-resource-headers" "${webassembly_files}")
add_header_target("x86-resource-headers" "${x86_files}")
Expand Down Expand Up @@ -538,6 +542,11 @@ install(
DESTINATION ${header_install_dir}/openmp_wrappers
COMPONENT clang-resource-headers)

install(
FILES ${zos_wrapper_files}
DESTINATION ${header_install_dir}/zos_wrappers
COMPONENT clang-resource-headers)

#############################################################
# Install rules for separate header lists
install(
Expand Down Expand Up @@ -642,6 +651,12 @@ install(
EXCLUDE_FROM_ALL
COMPONENT systemz-resource-headers)

install(
FILES ${zos_wrapper_files}
DESTINATION ${header_install_dir}/zos_wrappers
EXCLUDE_FROM_ALL
COMPONENT systemz-resource-headers)

install(
FILES ${ve_files}
DESTINATION ${header_install_dir}
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Headers/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
#ifndef __BUILTINS_H
#define __BUILTINS_H

#if defined(__MVS__) && __has_include_next(<builtins.h>)
#include_next <builtins.h>
#endif /* __MVS__ */
#endif /* __BUILTINS_H */
5 changes: 5 additions & 0 deletions clang/lib/Headers/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#ifndef __CLANG_FLOAT_H
#define __CLANG_FLOAT_H

#if defined(__MVS__) && __has_include_next(<float.h>)
#include_next <float.h>
#else

/* If we're on MinGW, fall back to the system's float.h, which might have
* additional definitions provided for Windows.
* For more details see http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx
Expand Down Expand Up @@ -165,4 +169,5 @@
# define FLT16_TRUE_MIN __FLT16_TRUE_MIN__
#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */

#endif /* __MVS__ */
#endif /* __CLANG_FLOAT_H */
4 changes: 4 additions & 0 deletions clang/lib/Headers/inttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#if !defined(_AIX) || !defined(_STD_TYPES_T)
#define __CLANG_INTTYPES_H
#endif
#if defined(__MVS__) && __has_include_next(<inttypes.h>)
#include_next <inttypes.h>
#else

#if defined(_MSC_VER) && _MSC_VER < 1800
#error MSVC does not have inttypes.h prior to Visual Studio 2013
Expand Down Expand Up @@ -94,4 +97,5 @@
#define SCNxFAST32 "x"
#endif

#endif /* __MVS__ */
#endif /* __CLANG_INTTYPES_H */
4 changes: 4 additions & 0 deletions clang/lib/Headers/iso646.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#ifndef __ISO646_H
#define __ISO646_H
#if defined(__MVS__) && __has_include_next(<iso646.h>)
#include_next <iso646.h>
#else

#ifndef __cplusplus
#define and &&
Expand All @@ -24,4 +27,5 @@
#define xor_eq ^=
#endif

#endif /* __MVS__ */
#endif /* __ISO646_H */
5 changes: 5 additions & 0 deletions clang/lib/Headers/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#ifndef __CLANG_LIMITS_H
#define __CLANG_LIMITS_H

#if defined(__MVS__) && __has_include_next(<limits.h>)
#include_next <limits.h>
#else

/* The system's limits.h may, in turn, try to #include_next GCC's limits.h.
Avert this #include_next madness. */
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
Expand Down Expand Up @@ -122,4 +126,5 @@
#define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
#endif

#endif /* __MVS__ */
#endif /* __CLANG_LIMITS_H */
5 changes: 5 additions & 0 deletions clang/lib/Headers/stdalign.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#ifndef __STDALIGN_H
#define __STDALIGN_H

#if defined(__MVS__) && __has_include_next(<stdalign.h>)
#include_next <stdalign.h>
#else

#if defined(__cplusplus) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L)
#ifndef __cplusplus
Expand All @@ -21,4 +25,5 @@
#define __alignof_is_defined 1
#endif /* __STDC_VERSION__ */

#endif /* __MVS__ */
#endif /* __STDALIGN_H */
12 changes: 12 additions & 0 deletions clang/lib/Headers/stdarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
defined(__need_va_arg) || defined(__need___va_copy) || \
defined(__need_va_copy)

#if defined(__MVS__) && __has_include_next(<stdarg.h>)
#define __STDARG_H
#undef __need___va_list
#undef __need_va_list
#undef __need_va_arg
#undef __need___va_copy
#undef __need_va_copy
#include_next <stdarg.h>

#else
#if !defined(__need___va_list) && !defined(__need_va_list) && \
!defined(__need_va_arg) && !defined(__need___va_copy) && \
!defined(__need_va_copy)
Expand Down Expand Up @@ -76,4 +86,6 @@
#undef __need_va_copy
#endif /* defined(__need_va_copy) */

#endif /* __MVS__ */

#endif
5 changes: 5 additions & 0 deletions clang/lib/Headers/stdbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#define __bool_true_false_are_defined 1

#if defined(__MVS__) && __has_include_next(<stdbool.h>)
#include_next <stdbool.h>
#else

#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
/* FIXME: We should be issuing a deprecation warning here, but cannot yet due
* to system headers which include this header file unconditionally.
Expand All @@ -31,4 +35,5 @@
#endif
#endif

#endif /* __MVS__ */
#endif /* __STDBOOL_H */
17 changes: 17 additions & 0 deletions clang/lib/Headers/stddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@
defined(__need_unreachable) || defined(__need_max_align_t) || \
defined(__need_offsetof) || defined(__need_wint_t)

#if defined(__MVS__) && __has_include_next(<stddef.h>)
#define __STDDEF_H
#undef __need_ptrdiff_t
#undef __need_size_t
#undef __need_rsize_t
#undef __need_wchar_t
#undef __need_NULL
#undef __need_nullptr_t
#undef __need_unreachable
#undef __need_max_align_t
#undef __need_offsetof
#undef __need_wint_t
#include_next <stddef.h>

#else

#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
!defined(__need_rsize_t) && !defined(__need_wchar_t) && \
!defined(__need_NULL) && !defined(__need_nullptr_t) && \
Expand Down Expand Up @@ -120,4 +136,5 @@ __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
#undef __need_wint_t
#endif /* __need_wint_t */

#endif /* __MVS__ */
#endif
5 changes: 5 additions & 0 deletions clang/lib/Headers/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#define __CLANG_STDINT_H
#endif

#if defined(__MVS__) && __has_include_next(<stdint.h>)
#include_next <stdint.h>
#else

/* If we're hosted, fall back to the system's stdint.h, which might have
* additional definitions.
*/
Expand Down Expand Up @@ -947,4 +951,5 @@ typedef __UINTMAX_TYPE__ uintmax_t;
#endif

#endif /* __STDC_HOSTED__ */
#endif /* __MVS__ */
#endif /* __CLANG_STDINT_H */
6 changes: 6 additions & 0 deletions clang/lib/Headers/stdnoreturn.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
#ifndef __STDNORETURN_H
#define __STDNORETURN_H

#if defined(__MVS__) && __has_include_next(<stdnoreturn.h>)
#include_next <stdnoreturn.h>
#else

#define noreturn _Noreturn
#define __noreturn_is_defined 1

#endif /* __MVS__ */

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L) && \
!defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
/* The noreturn macro is deprecated in C23. We do not mark it as such because
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Headers/varargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
*/
#ifndef __VARARGS_H
#define __VARARGS_H
#error "Please use <stdarg.h> instead of <varargs.h>"
#if defined(__MVS__) && __has_include_next(<varargs.h>)
#include_next <varargs.h>
#else
#error "Please use <stdarg.h> instead of <varargs.h>"
#endif /* __MVS__ */
#endif
18 changes: 18 additions & 0 deletions clang/lib/Headers/zos_wrappers/builtins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*===---- builtins.h - z/Architecture Builtin Functions --------------------===
*
* 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_BUILTINS_H
#define __ZOS_WRAPPERS_BUILTINS_H
#if defined(__MVS__)
#include_next <builtins.h>
#if defined(__VEC__)
#include <vecintrin.h>
#endif
#endif /* defined(__MVS__) */
#endif /* __ZOS_WRAPPERS_BUILTINS_H */