Author: Matheus Izvekov Date: 2022-09-06T19:27:37+02:00 New Revision: 94c6dfbaebbd5b9474794b2437757dfb6aedefc3
URL: https://github.com/llvm/llvm-project/commit/94c6dfbaebbd5b9474794b2437757dfb6aedefc3 DIFF: https://github.com/llvm/llvm-project/commit/94c6dfbaebbd5b9474794b2437757dfb6aedefc3.diff LOG: [clang] Implement setting crash_diagnostics_dir through env variable This implements setting the equivalent of `-fcrash-diagnostics-dir` through the environment variable `CLANG_CRASH_DIAGNOSTICS_DIR`. If present, the flag still takes precedence. This helps integration with test frameworks and pipelines. With this feature, we change the libcxx bootstrapping build pipeline to produce clang crash reproducers as artifacts. Signed-off-by: Matheus Izvekov <mizve...@gmail.com> Differential Revision: https://reviews.llvm.org/D133082 Added: clang/test/Driver/crash-diagnostics-dir-3.c Modified: clang/docs/ReleaseNotes.rst clang/docs/UsersManual.rst clang/lib/Driver/Driver.cpp libcxx/utils/ci/buildkite-pipeline.yml Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 146b2149f9d7e..1d381649b6bb4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -135,6 +135,9 @@ Improvements to Clang's diagnostics Non-comprehensive list of changes in this release ------------------------------------------------- +- It's now possible to set the crash diagnostics directory through + the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``. + The ``-fcrash-diagnostics-dir`` flag takes precedence. New Compiler Flags ------------------ diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index bf17677274e0c..8afe5cab64cb5 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -687,6 +687,11 @@ of generating a delta reduced test case. Specify where to write the crash diagnostics files; defaults to the usual location for temporary files. +.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=<dir> + + Like :option:`-fcrash-diagnostics-dir=<dir>`, specifies where to write the + crash diagnostics files, but with lower precedence than the option. + Clang is also capable of generating preprocessed source file(s) and associated run script(s) even without a crash. This is specially useful when trying to generate a reproducer for warnings or errors while using modules. diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 0a61b5e2d62d4..3743515d3d43f 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5413,15 +5413,18 @@ const char *Driver::CreateTempFile(Compilation &C, StringRef Prefix, StringRef BoundArch) const { SmallString<128> TmpName; Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir); - if (CCGenDiagnostics && A) { - SmallString<128> CrashDirectory(A->getValue()); - if (!getVFS().exists(CrashDirectory)) - llvm::sys::fs::create_directories(CrashDirectory); - llvm::sys::path::append(CrashDirectory, Prefix); + Optional<std::string> CrashDirectory = + CCGenDiagnostics && A + ? std::string(A->getValue()) + : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR"); + if (CrashDirectory) { + if (!getVFS().exists(*CrashDirectory)) + llvm::sys::fs::create_directories(*CrashDirectory); + SmallString<128> Path(*CrashDirectory); + llvm::sys::path::append(Path, Prefix); const char *Middle = !Suffix.empty() ? "-%%%%%%." : "-%%%%%%"; - std::error_code EC = llvm::sys::fs::createUniqueFile( - CrashDirectory + Middle + Suffix, TmpName); - if (EC) { + if (std::error_code EC = + llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) { Diag(clang::diag::err_unable_to_make_temp) << EC.message(); return ""; } diff --git a/clang/test/Driver/crash-diagnostics-dir-3.c b/clang/test/Driver/crash-diagnostics-dir-3.c new file mode 100644 index 0000000000000..9529e30021045 --- /dev/null +++ b/clang/test/Driver/crash-diagnostics-dir-3.c @@ -0,0 +1,5 @@ +// 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 diff --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml index d15172980e612..61951720ef650 100644 --- a/libcxx/utils/ci/buildkite-pipeline.yml +++ b/libcxx/utils/ci/buildkite-pipeline.yml @@ -369,10 +369,12 @@ steps: artifact_paths: - "**/test-results.xml" - "**/*.abilist" + - "**/crash_diagnostics/*" env: CC: "clang-${LLVM_HEAD_VERSION}" CXX: "clang++-${LLVM_HEAD_VERSION}" LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}" + CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics" agents: queue: "libcxx-builders" os: "linux" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits