xingxue-ibm wrote:
Hi @hnrklssn @fhahn,
This patch changes Clang’s behavior so its exit code indicates termination by a
signal rather than a normal compilation error in case it is terminated by a
signal. The tests in the list are intended to cause Clang to be terminated by a
signal. For example, in `clang/test/test/Driver/crash-diagnostics-dir-3.c`, the
directive `#pragma clang __debug parser_crash` causes Clang to terminate with
signal SIGTRAP. However, prior to this patch, Clang exited with a code like an
error in compilation:
```
clang: error: clang frontend command failed with exit code 133 (use -v to see
invocation)
```
So, the original test case did not expect a crash:
```
// RUN: export LSAN_OPTIONS=detect_leaks=0
// RUN: rm -rf %t
// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 |
FileCheck %s
#pragma clang __debug parser_crash
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
// CHECK: diagnostic msg:
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
```
With this patch, Clang exits with an exit code indicating it was terminated by
a signal as specified by POSIX:
```
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
```
Thus, this patch changes the test case to expect a crash accordingly. The
`%crash_opt` macro is `--crash` on Unix‑like targets and blank on Windows
because Clang’s behavior remains unchanged on the Windows target.
```
// RUN: export LSAN_OPTIONS=detect_leaks=0
// RUN: rm -rf %t
// RUN: not %crash_opt env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o -
2>&1 | FileCheck %s
#pragma clang __debug parser_crash
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
// CHECK: diagnostic msg:
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
```
We built the Clang compiler with this patch on a macOS system, and the listed
test cases passed for us.
The Clang compiler not containing this patch would fail the updated test cases
because its exit code does not indicate termination by a signal.
We built the Clang compiler with this patch on a macOS system, and the listed
test cases passed for us.
Could you compile the test case
`llvm-project/clang/test/Driver/crash-diagnostics-dir-3.c` with the same
compiler used in the test run and share the output? For example:
```
<path-to-clang-for-test-run>/clang -c
<path-to-llvm>/llvm-project/clang/test/Driver/crash-diagnostics-dir-3.c
```
https://github.com/llvm/llvm-project/pull/169340
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits