Skip to content

Commit 4acec9c

Browse files
committed
Don't install signal handler if the disposition of a signal is SIG_IGN, resignal after the signal handler handles a signal so the exit code of the compiler contains the signal number.
1 parent d5927a6 commit 4acec9c

File tree

14 files changed

+75
-29
lines changed

14 files changed

+75
-29
lines changed

clang-tools-extra/clangd/unittests/ThreadCrashReporterTests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
#include <csignal>
1414
#include <string>
1515

16+
// According to the POSIX specification, if the inherited disposition of a
17+
// signal is the default action, the behavior of utilitys must be as if the
18+
// default action had been taken. When the required default action is to
19+
// terminate the process, such as for SIGUSR1, the utility may catch the
20+
// signal, perform additional processing, restore the default disposition,
21+
// and then re-signal itself. This causes the process to terminate as
22+
// required. Because of this behavior, the crash-reporter test here is not
23+
// suitable for Unix platforms.
24+
25+
#ifndef LLVM_ON_UNIX
26+
1627
namespace clang {
1728
namespace clangd {
1829

@@ -76,3 +87,4 @@ TEST(ThreadCrashReporterTest, All) {
7687
} // namespace
7788
} // namespace clangd
7889
} // namespace clang
90+
#endif // !LLVM_ON_UNIX

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,14 @@ int Driver::ExecuteCompilation(
22982298

22992299
if (!FailingCommand->getCreator().hasGoodDiagnostics() || CommandRes != 1) {
23002300
// FIXME: See FIXME above regarding result code interpretation.
2301+
#if LLVM_ON_UNIX
2302+
// On Unix, signals are represented by return codes of 128 plus the
2303+
// signal number. Return code 255 is excluded because some tools,
2304+
// such as llvm-ifs, exit with code 255 (-1) on failure.
2305+
if (CommandRes > 128 && CommandRes != 255)
2306+
#else
23012307
if (CommandRes < 0)
2308+
#endif
23022309
Diag(clang::diag::err_drv_command_signalled)
23032310
<< FailingTool.getShortName();
23042311
else
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: export LSAN_OPTIONS=detect_leaks=0
22
// RUN: rm -rf %t
3-
// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | FileCheck %s
3+
// RUN: not --crash env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | FileCheck %s
44
#pragma clang __debug parser_crash
55
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
66
// CHECK: diagnostic msg: {{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: export LSAN_OPTIONS=detect_leaks=0
22
// RUN: rm -rf %t
3-
// RUN: not %clang -fcrash-diagnostics-dir=%t -c %s -o - 2>&1 | FileCheck %s
3+
// RUN: not --crash %clang -fcrash-diagnostics-dir=%t -c %s -o - 2>&1 | FileCheck %s
44
#pragma clang __debug parser_crash
55
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
66
// CHECK: diagnostic msg: {{.*}}{{/|\\}}crash-diagnostics-dir.c.tmp{{(/|\\).*}}.c

clang/test/Driver/crash-report-clang-cl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: rm -rf %t
33
// RUN: mkdir %t
44

5-
// RUN: not %clang_cl -fsyntax-only /Brepro /source-charset:utf-8 \
5+
// RUN: not --crash %clang_cl -fsyntax-only /Brepro /source-charset:utf-8 \
66
// RUN: -fcrash-diagnostics-dir=%t -- %s 2>&1 | FileCheck %s
77
// RUN: cat %t/crash-report-clang-cl-*.cpp | FileCheck --check-prefix=CHECKSRC %s
88
// RUN: cat %t/crash-report-clang-cl-*.sh | FileCheck --check-prefix=CHECKSH %s

clang/test/Driver/crash-report-header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: export LSAN_OPTIONS=detect_leaks=0
22
// RUN: rm -rf %t
33
// RUN: mkdir %t
4-
// RUN: env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 not %clang -fsyntax-only %s 2>&1 | FileCheck %s
4+
// RUN: env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 not --crash %clang -fsyntax-only %s 2>&1 | FileCheck %s
55
// RUN: cat %t/crash-report-header-*.h | FileCheck --check-prefix=CHECKSRC "%s"
66
// RUN: cat %t/crash-report-header-*.sh | FileCheck --check-prefix=CHECKSH "%s"
77
// REQUIRES: crash-recovery

clang/test/Driver/crash-report-spaces.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: rm -rf "%t"
33
// RUN: mkdir "%t"
44
// RUN: cp "%s" "%t/crash report spaces.c"
5-
// RUN: env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 not %clang -fsyntax-only "%t/crash report spaces.c" 2>&1 | FileCheck "%s"
5+
// RUN: env TMPDIR="%t" TEMP="%t" TMP="%t" RC_DEBUG_OPTIONS=1 not --crash %clang -fsyntax-only "%t/crash report spaces.c" 2>&1 | FileCheck "%s"
66
// RUN: cat "%t/crash report spaces"-*.c | FileCheck --check-prefix=CHECKSRC "%s"
77
// RUN: cat "%t/crash report spaces"-*.sh | FileCheck --check-prefix=CHECKSH "%s"
88
// REQUIRES: crash-recovery

clang/test/Driver/crash-report-with-asserts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \
1414
// RUN: CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \
15-
// RUN: not %clang %s @%t.rsp -DASSERT 2>&1 | FileCheck %s
15+
// RUN: not --crash %clang %s @%t.rsp -DASSERT 2>&1 | FileCheck %s
1616
// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s
1717
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s
1818

1919
// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \
2020
// RUN: CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \
21-
// RUN: not %clang %s @%t.rsp -DUNREACHABLE 2>&1 | FileCheck %s
21+
// RUN: not --crash %clang %s @%t.rsp -DUNREACHABLE 2>&1 | FileCheck %s
2222
// RUN: cat %t/crash-report-with-asserts-*.c | FileCheck --check-prefix=CHECKSRC %s
2323
// RUN: cat %t/crash-report-with-asserts-*.sh | FileCheck --check-prefix=CHECKSH %s
2424

clang/test/Driver/crash-report.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \
1414
// RUN: CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \
15-
// RUN: not %clang %s @%t.rsp -DPARSER 2>&1 | FileCheck %s
15+
// RUN: not --crash %clang %s @%t.rsp -DPARSER 2>&1 | FileCheck %s
1616
// RUN: cat %t/crash-report-*.cpp | FileCheck --check-prefix=CHECKSRC %s
1717
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s
1818

1919
// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \
2020
// RUN: CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1 \
21-
// RUN: not %clang %s @%t.rsp -DCRASH 2>&1 | FileCheck %s
21+
// RUN: not --crash %clang %s @%t.rsp -DCRASH 2>&1 | FileCheck %s
2222
// RUN: cat %t/crash-report-*.cpp | FileCheck --check-prefix=CHECKSRC %s
2323
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s
2424

clang/test/Driver/emit-reproducer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
// RUN: echo "%s -fcrash-diagnostics-dir=%t -fsyntax-only" | sed -e 's/\\/\\\\/g' > %t.rsp
55

6-
// RUN: not %clang -DFATAL @%t.rsp -gen-reproducer=off 2>&1 | FileCheck %s --check-prefix=NOT
7-
// RUN: not %clang -DFATAL @%t.rsp -fno-crash-diagnostics 2>&1 | FileCheck %s --check-prefix=NOT
8-
// RUN: not %clang -DFATAL @%t.rsp 2>&1 | FileCheck %s
9-
// RUN: not %clang -DFATAL @%t.rsp -gen-reproducer=crash 2>&1 | FileCheck %s
10-
// RUN: not %clang -DFATAL @%t.rsp -gen-reproducer=error 2>&1 | FileCheck %s
11-
// RUN: not %clang -DFATAL @%t.rsp -gen-reproducer=always 2>&1 | FileCheck %s
12-
// RUN: not %clang -DFATAL @%t.rsp -gen-reproducer 2>&1 | FileCheck %s
6+
// RUN: not --crash %clang -DFATAL @%t.rsp -gen-reproducer=off 2>&1 | FileCheck %s --check-prefix=NOT
7+
// RUN: not --crash %clang -DFATAL @%t.rsp -fno-crash-diagnostics 2>&1 | FileCheck %s --check-prefix=NOT
8+
// RUN: not --crash %clang -DFATAL @%t.rsp 2>&1 | FileCheck %s
9+
// RUN: not --crash %clang -DFATAL @%t.rsp -gen-reproducer=crash 2>&1 | FileCheck %s
10+
// RUN: not --crash %clang -DFATAL @%t.rsp -gen-reproducer=error 2>&1 | FileCheck %s
11+
// RUN: not --crash %clang -DFATAL @%t.rsp -gen-reproducer=always 2>&1 | FileCheck %s
12+
// RUN: not --crash %clang -DFATAL @%t.rsp -gen-reproducer 2>&1 | FileCheck %s
1313

1414
// RUN: not %clang -DERROR @%t.rsp -gen-reproducer=off 2>&1 | FileCheck %s --check-prefix=NOT
1515
// RUN: not %clang -DERROR @%t.rsp -fno-crash-diagnostics 2>&1 | FileCheck %s --check-prefix=NOT

0 commit comments

Comments
 (0)