Skip to content

Commit df241b1

Browse files
authored
[z/OS] add support for z/OS system headers to clang std header wrappers (#89995)
Update the wrappers for the C std headers so that they always forward to the z/OS system headers.
1 parent 442990b commit df241b1

File tree

14 files changed

+111
-3
lines changed

14 files changed

+111
-3
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ set(llvm_libc_wrapper_files
335335
llvm_libc_wrappers/time.h
336336
)
337337

338+
set(zos_wrapper_files
339+
zos_wrappers/builtins.h
340+
)
341+
338342
include(GetClangResourceDir)
339343
get_clang_resource_dir(output_dir PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
340344
set(out_files)
@@ -370,7 +374,7 @@ endfunction(clang_generate_header)
370374

371375
# Copy header files from the source directory to the build directory
372376
foreach( f ${files} ${cuda_wrapper_files} ${cuda_wrapper_bits_files}
373-
${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files}
377+
${ppc_wrapper_files} ${openmp_wrapper_files} ${zos_wrapper_files} ${hlsl_files}
374378
${llvm_libc_wrapper_files})
375379
copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
376380
endforeach( f )
@@ -487,7 +491,7 @@ add_header_target("mips-resource-headers" "${mips_msa_files}")
487491
add_header_target("ppc-resource-headers" "${ppc_files};${ppc_wrapper_files}")
488492
add_header_target("ppc-htm-resource-headers" "${ppc_htm_files}")
489493
add_header_target("riscv-resource-headers" "${riscv_files};${riscv_generated_files}")
490-
add_header_target("systemz-resource-headers" "${systemz_files}")
494+
add_header_target("systemz-resource-headers" "${systemz_files};${zos_wrapper_files}")
491495
add_header_target("ve-resource-headers" "${ve_files}")
492496
add_header_target("webassembly-resource-headers" "${webassembly_files}")
493497
add_header_target("x86-resource-headers" "${x86_files}")
@@ -538,6 +542,11 @@ install(
538542
DESTINATION ${header_install_dir}/openmp_wrappers
539543
COMPONENT clang-resource-headers)
540544

545+
install(
546+
FILES ${zos_wrapper_files}
547+
DESTINATION ${header_install_dir}/zos_wrappers
548+
COMPONENT clang-resource-headers)
549+
541550
#############################################################
542551
# Install rules for separate header lists
543552
install(
@@ -642,6 +651,12 @@ install(
642651
EXCLUDE_FROM_ALL
643652
COMPONENT systemz-resource-headers)
644653

654+
install(
655+
FILES ${zos_wrapper_files}
656+
DESTINATION ${header_install_dir}/zos_wrappers
657+
EXCLUDE_FROM_ALL
658+
COMPONENT systemz-resource-headers)
659+
645660
install(
646661
FILES ${ve_files}
647662
DESTINATION ${header_install_dir}

clang/lib/Headers/builtins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
#ifndef __BUILTINS_H
1414
#define __BUILTINS_H
1515

16+
#if defined(__MVS__) && __has_include_next(<builtins.h>)
17+
#include_next <builtins.h>
18+
#endif /* __MVS__ */
1619
#endif /* __BUILTINS_H */

clang/lib/Headers/float.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#ifndef __CLANG_FLOAT_H
1111
#define __CLANG_FLOAT_H
1212

13+
#if defined(__MVS__) && __has_include_next(<float.h>)
14+
#include_next <float.h>
15+
#else
16+
1317
/* If we're on MinGW, fall back to the system's float.h, which might have
1418
* additional definitions provided for Windows.
1519
* For more details see http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx
@@ -165,4 +169,5 @@
165169
# define FLT16_TRUE_MIN __FLT16_TRUE_MIN__
166170
#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
167171

172+
#endif /* __MVS__ */
168173
#endif /* __CLANG_FLOAT_H */

clang/lib/Headers/inttypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#if !defined(_AIX) || !defined(_STD_TYPES_T)
1414
#define __CLANG_INTTYPES_H
1515
#endif
16+
#if defined(__MVS__) && __has_include_next(<inttypes.h>)
17+
#include_next <inttypes.h>
18+
#else
1619

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

100+
#endif /* __MVS__ */
97101
#endif /* __CLANG_INTTYPES_H */

clang/lib/Headers/iso646.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#ifndef __ISO646_H
1111
#define __ISO646_H
12+
#if defined(__MVS__) && __has_include_next(<iso646.h>)
13+
#include_next <iso646.h>
14+
#else
1215

1316
#ifndef __cplusplus
1417
#define and &&
@@ -24,4 +27,5 @@
2427
#define xor_eq ^=
2528
#endif
2629

30+
#endif /* __MVS__ */
2731
#endif /* __ISO646_H */

clang/lib/Headers/limits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#ifndef __CLANG_LIMITS_H
1010
#define __CLANG_LIMITS_H
1111

12+
#if defined(__MVS__) && __has_include_next(<limits.h>)
13+
#include_next <limits.h>
14+
#else
15+
1216
/* The system's limits.h may, in turn, try to #include_next GCC's limits.h.
1317
Avert this #include_next madness. */
1418
#if defined __GNUC__ && !defined _GCC_LIMITS_H_
@@ -122,4 +126,5 @@
122126
#define ULONG_LONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
123127
#endif
124128

129+
#endif /* __MVS__ */
125130
#endif /* __CLANG_LIMITS_H */

clang/lib/Headers/stdalign.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#ifndef __STDALIGN_H
1111
#define __STDALIGN_H
1212

13+
#if defined(__MVS__) && __has_include_next(<stdalign.h>)
14+
#include_next <stdalign.h>
15+
#else
16+
1317
#if defined(__cplusplus) || \
1418
(defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L)
1519
#ifndef __cplusplus
@@ -21,4 +25,5 @@
2125
#define __alignof_is_defined 1
2226
#endif /* __STDC_VERSION__ */
2327

28+
#endif /* __MVS__ */
2429
#endif /* __STDALIGN_H */

clang/lib/Headers/stdarg.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
defined(__need_va_arg) || defined(__need___va_copy) || \
3434
defined(__need_va_copy)
3535

36+
#if defined(__MVS__) && __has_include_next(<stdarg.h>)
37+
#define __STDARG_H
38+
#undef __need___va_list
39+
#undef __need_va_list
40+
#undef __need_va_arg
41+
#undef __need___va_copy
42+
#undef __need_va_copy
43+
#include_next <stdarg.h>
44+
45+
#else
3646
#if !defined(__need___va_list) && !defined(__need_va_list) && \
3747
!defined(__need_va_arg) && !defined(__need___va_copy) && \
3848
!defined(__need_va_copy)
@@ -76,4 +86,6 @@
7686
#undef __need_va_copy
7787
#endif /* defined(__need_va_copy) */
7888

89+
#endif /* __MVS__ */
90+
7991
#endif

clang/lib/Headers/stdbool.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
#define __bool_true_false_are_defined 1
1414

15+
#if defined(__MVS__) && __has_include_next(<stdbool.h>)
16+
#include_next <stdbool.h>
17+
#else
18+
1519
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
1620
/* FIXME: We should be issuing a deprecation warning here, but cannot yet due
1721
* to system headers which include this header file unconditionally.
@@ -31,4 +35,5 @@
3135
#endif
3236
#endif
3337

38+
#endif /* __MVS__ */
3439
#endif /* __STDBOOL_H */

clang/lib/Headers/stddef.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@
3636
defined(__need_unreachable) || defined(__need_max_align_t) || \
3737
defined(__need_offsetof) || defined(__need_wint_t)
3838

39+
#if defined(__MVS__) && __has_include_next(<stddef.h>)
40+
#define __STDDEF_H
41+
#undef __need_ptrdiff_t
42+
#undef __need_size_t
43+
#undef __need_rsize_t
44+
#undef __need_wchar_t
45+
#undef __need_NULL
46+
#undef __need_nullptr_t
47+
#undef __need_unreachable
48+
#undef __need_max_align_t
49+
#undef __need_offsetof
50+
#undef __need_wint_t
51+
#include_next <stddef.h>
52+
53+
#else
54+
3955
#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \
4056
!defined(__need_rsize_t) && !defined(__need_wchar_t) && \
4157
!defined(__need_NULL) && !defined(__need_nullptr_t) && \
@@ -120,4 +136,5 @@ __WINT_TYPE__ directly; accommodate both by requiring __need_wint_t */
120136
#undef __need_wint_t
121137
#endif /* __need_wint_t */
122138

139+
#endif /* __MVS__ */
123140
#endif

clang/lib/Headers/stdint.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#define __CLANG_STDINT_H
1515
#endif
1616

17+
#if defined(__MVS__) && __has_include_next(<stdint.h>)
18+
#include_next <stdint.h>
19+
#else
20+
1721
/* If we're hosted, fall back to the system's stdint.h, which might have
1822
* additional definitions.
1923
*/
@@ -947,4 +951,5 @@ typedef __UINTMAX_TYPE__ uintmax_t;
947951
#endif
948952

949953
#endif /* __STDC_HOSTED__ */
954+
#endif /* __MVS__ */
950955
#endif /* __CLANG_STDINT_H */

clang/lib/Headers/stdnoreturn.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
#ifndef __STDNORETURN_H
1111
#define __STDNORETURN_H
1212

13+
#if defined(__MVS__) && __has_include_next(<stdnoreturn.h>)
14+
#include_next <stdnoreturn.h>
15+
#else
16+
1317
#define noreturn _Noreturn
1418
#define __noreturn_is_defined 1
1519

20+
#endif /* __MVS__ */
21+
1622
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L) && \
1723
!defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
1824
/* The noreturn macro is deprecated in C23. We do not mark it as such because

clang/lib/Headers/varargs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
*/
99
#ifndef __VARARGS_H
1010
#define __VARARGS_H
11-
#error "Please use <stdarg.h> instead of <varargs.h>"
11+
#if defined(__MVS__) && __has_include_next(<varargs.h>)
12+
#include_next <varargs.h>
13+
#else
14+
#error "Please use <stdarg.h> instead of <varargs.h>"
15+
#endif /* __MVS__ */
1216
#endif
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*===---- builtins.h - z/Architecture Builtin Functions --------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __ZOS_WRAPPERS_BUILTINS_H
11+
#define __ZOS_WRAPPERS_BUILTINS_H
12+
#if defined(__MVS__)
13+
#include_next <builtins.h>
14+
#if defined(__VEC__)
15+
#include <vecintrin.h>
16+
#endif
17+
#endif /* defined(__MVS__) */
18+
#endif /* __ZOS_WRAPPERS_BUILTINS_H */

0 commit comments

Comments
 (0)