Files
llvm-project/llvm/cmake/modules/llvm-driver-template.cpp.in
Xing Xue 15488a7f78 [LLVM][CLANG] Update signal-handling behavior to comply with POSIX (#169340)
The POSIX standard
[POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap01.html#tag_18)
specifies how the utility reacts to signals as follows. This includes
clang when invoke through a invocation such as
[c17](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/c17.html)
```
ASYNCHRONOUS EVENTS

    The ASYNCHRONOUS EVENTS section lists how the utility reacts to such events as signals and what signals are caught.

    Default Behavior: When this section is listed as "Default.", or it refers to "the standard action" for any signal, it means that the action taken as a result of the signal shall be as follows:

        If the action inherited from the invoking process, according to the rules of inheritance of signal actions defined in the System Interfaces volume of POSIX.1-2024, is for the signal to be ignored, the utility shall ignore the signal.
        If the action inherited from the invoking process, according to the rules of inheritance of signal actions defined in System Interfaces volume of POSIX.1-2024, is the default signal action, the result of the utility's execution shall be as if the default signal action had been taken.

    When the required action is for the signal to terminate the utility, the utility may catch the signal, perform some additional processing (such as deleting temporary files), restore the default signal action, and resignal itself.
```
This PR updates the LLVM/Clang’s behavior accordingly by not installing
a signal handler when the inherited disposition is `SIG_IGN`, and by
ensuring that the exit code reflects the terminating signal number,
resignaling after the signal is handled. Additionally, test cases have
been updated to expect failures due to signals/crashes rather than
regular errors.


[<signal.h>](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/signal.h.html)
specifies the default action of signals.
2026-02-18 13:52:07 -05:00

19 lines
692 B
C++

//===-- driver-template.cpp -----------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/LLVMDriver.h"
int @TOOL_NAME@_main(int argc, char **, const llvm::ToolContext &);
int main(int argc, char **argv) {
llvm::InitLLVM X(argc, argv@INITLLVM_ARGS@);
return @TOOL_NAME@_main(argc, argv, {argv[0], nullptr, false});
}