Skip to content

Commit ed07e1f

Browse files
committed
[SystemZ/ZOS] Add header file to encapsulate use of <sysexits.h>
The non-standard header file `<sysexits.h>` provides some return values. `EX_IOERR` is used to as a special value to signal a broken pipe to the clang driver. On z/OS Unix System Services, this header file does not exists. This patch - adds a check for `<sysexits.h>`, removing the dependency on `LLVM_ON_UNIX` - adds a new header file `llvm/Support/ExitCodes`, which either includes `<sysexits.h>` or defines `EX_IOERR` - updates the users of `EX_IOERR` to include the new header file Reviewed By: hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D83472
1 parent 2392ff0 commit ed07e1f

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "llvm/Option/Option.h"
7272
#include "llvm/Support/CommandLine.h"
7373
#include "llvm/Support/ErrorHandling.h"
74+
#include "llvm/Support/ExitCodes.h"
7475
#include "llvm/Support/FileSystem.h"
7576
#include "llvm/Support/FormatVariadic.h"
7677
#include "llvm/Support/Host.h"
@@ -87,7 +88,6 @@
8788
#include <utility>
8889
#if LLVM_ON_UNIX
8990
#include <unistd.h> // getpid
90-
#include <sysexits.h> // EX_IOERR
9191
#endif
9292

9393
using namespace clang::driver;

llvm/cmake/config-ix.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
5454
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
5555
check_include_file(sys/time.h HAVE_SYS_TIME_H)
5656
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
57+
check_include_file(sysexits.h HAVE_SYSEXITS_H)
5758
check_include_file(termios.h HAVE_TERMIOS_H)
5859
check_include_file(unistd.h HAVE_UNISTD_H)
5960
check_include_file(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)

llvm/include/llvm/Config/config.h.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
/* Define to 1 if you have the <sys/types.h> header file. */
209209
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
210210

211+
/* Define to 1 if you have the <sysexits.h> header file. */
212+
#cmakedefine HAVE_SYSEXITS_H ${HAVE_SYSEXITS_H}
213+
211214
/* Define if the setupterm() function is supported this platform. */
212215
#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO}
213216

llvm/include/llvm/Support/ExitCodes.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- llvm/Support/ExitCodes.h - Exit codes for exit() -------*- C++ -*-===//
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+
/// \file
10+
/// This file contains definitions of exit codes for exit() function. They are
11+
/// either defined by sysexits.h if it is supported, or defined here if
12+
/// sysexits.h is not supported.
13+
///
14+
//===----------------------------------------------------------------------===//
15+
16+
#ifndef LLVM_SUPPORT_EXITCODES_H
17+
#define LLVM_SUPPORT_EXITCODES_H
18+
19+
#include "llvm/Config/config.h"
20+
21+
#if HAVE_SYSEXITS_H
22+
#include <sysexits.h>
23+
#elif __MVS__
24+
// <sysexits.h> does not exist on z/OS. The only value used in LLVM is
25+
// EX_IOERR, which is used to signal a special error condition (broken pipe).
26+
// Define the macro with its usual value from BSD systems, which is chosen to
27+
// not clash with more standard exit codes like 1.
28+
#define EX_IOERR 74
29+
#elif LLVM_ON_UNIX
30+
#error Exit code EX_IOERR not available
31+
#endif
32+
33+
#endif

llvm/lib/Support/CrashRecoveryContext.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
#include "llvm/Support/CrashRecoveryContext.h"
1010
#include "llvm/Config/llvm-config.h"
1111
#include "llvm/Support/ErrorHandling.h"
12+
#include "llvm/Support/ExitCodes.h"
1213
#include "llvm/Support/ManagedStatic.h"
1314
#include "llvm/Support/Signals.h"
1415
#include "llvm/Support/ThreadLocal.h"
1516
#include <mutex>
1617
#include <setjmp.h>
17-
#if LLVM_ON_UNIX
18-
#include <sysexits.h> // EX_IOERR
19-
#endif
2018

2119
using namespace llvm;
2220

llvm/lib/Support/Unix/Signals.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "llvm/ADT/STLExtras.h"
3737
#include "llvm/Config/config.h"
3838
#include "llvm/Demangle/Demangle.h"
39+
#include "llvm/Support/ExitCodes.h"
3940
#include "llvm/Support/FileSystem.h"
4041
#include "llvm/Support/FileUtilities.h"
4142
#include "llvm/Support/Format.h"
@@ -46,7 +47,6 @@
4647
#include "llvm/Support/raw_ostream.h"
4748
#include <algorithm>
4849
#include <string>
49-
#include <sysexits.h>
5050
#ifdef HAVE_BACKTRACE
5151
# include BACKTRACE_HEADER // For backtrace().
5252
#endif

0 commit comments

Comments
 (0)