Author: Alex Brachet Date: 2022-11-03T00:12:10Z New Revision: 78ed64d89fd6ea348a963516a2e49028e4079f65
URL: https://github.com/llvm/llvm-project/commit/78ed64d89fd6ea348a963516a2e49028e4079f65 DIFF: https://github.com/llvm/llvm-project/commit/78ed64d89fd6ea348a963516a2e49028e4079f65.diff LOG: [Driver] Don't preprocess source files when reproducing linker crashes It's not necessary to redo the source file preprocessing for reproducing linker crashes because we must have successfully created the object file by this point. Skip this step, and also don't report the preprocessed source file or create the clang invocation shell script. The latter is no longer sensible without the preprocessed source, or helpful given the linker reproducer will have it's own shell script. Differential Revision: https://reviews.llvm.org/D137289 Added: Modified: clang/lib/Driver/Driver.cpp clang/test/Driver/lld-repro.c Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 80e6ec76d16f7..5704902b1cc5a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1527,6 +1527,11 @@ bool Driver::getCrashDiagnosticFile(StringRef ReproCrashFilename, return false; } +static const char BugReporMsg[] = + "\n********************\n\n" + "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n" + "Preprocessed source(s) and associated run script(s) are located at:"; + // When clang crashes, produce diagnostic information including the fully // preprocessed source file(s). Request that the developer attach the // diagnostic information to a bug report. @@ -1582,6 +1587,29 @@ void Driver::generateCompilationDiagnostics( // Suppress tool output. C.initCompilationForDiagnostics(); + // If lld failed, rerun it again with --reproduce. + if (IsLLD) { + const char *TmpName = CreateTempFile(C, "linker-crash", "tar"); + Command NewLLDInvocation = Cmd; + llvm::opt::ArgStringList ArgList = NewLLDInvocation.getArguments(); + StringRef ReproduceOption = + C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() + ? "/reproduce:" + : "--reproduce="; + ArgList.push_back(Saver.save(Twine(ReproduceOption) + TmpName).data()); + NewLLDInvocation.replaceArguments(std::move(ArgList)); + + // Redirect stdout/stderr to /dev/null. + NewLLDInvocation.Execute({None, {""}, {""}}, nullptr, nullptr); + Diag(clang::diag::note_drv_command_failed_diag_msg) << BugReporMsg; + Diag(clang::diag::note_drv_command_failed_diag_msg) << TmpName; + Diag(clang::diag::note_drv_command_failed_diag_msg) + << "\n\n********************"; + if (Report) + Report->TemporaryFiles.push_back(TmpName); + return; + } + // Construct the list of inputs. InputList Inputs; BuildInputs(C.getDefaultToolChain(), C.getArgs(), Inputs); @@ -1659,22 +1687,6 @@ void Driver::generateCompilationDiagnostics( return; } - // If lld failed, rerun it again with --reproduce. - if (IsLLD) { - const char *TmpName = CreateTempFile(C, "linker-crash", "tar"); - Command NewLLDInvocation = Cmd; - llvm::opt::ArgStringList ArgList = NewLLDInvocation.getArguments(); - StringRef ReproduceOption = - C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() - ? "/reproduce:" - : "--reproduce="; - ArgList.push_back(Saver.save(Twine(ReproduceOption) + TmpName).data()); - NewLLDInvocation.replaceArguments(std::move(ArgList)); - - // Redirect stdout/stderr to /dev/null. - NewLLDInvocation.Execute({None, {""}, {""}}, nullptr, nullptr); - } - const ArgStringList &TempFiles = C.getTempFiles(); if (TempFiles.empty()) { Diag(clang::diag::note_drv_command_failed_diag_msg) @@ -1682,10 +1694,7 @@ void Driver::generateCompilationDiagnostics( return; } - Diag(clang::diag::note_drv_command_failed_diag_msg) - << "\n********************\n\n" - "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n" - "Preprocessed source(s) and associated run script(s) are located at:"; + Diag(clang::diag::note_drv_command_failed_diag_msg) << BugReporMsg; SmallString<128> VFS; SmallString<128> ReproCrashFilename; diff --git a/clang/test/Driver/lld-repro.c b/clang/test/Driver/lld-repro.c index 7436d1a1f59be..1333f68d911ee 100644 --- a/clang/test/Driver/lld-repro.c +++ b/clang/test/Driver/lld-repro.c @@ -1,22 +1,28 @@ // REQUIRES: lld // UNSUPPORTED: ps4, ps5 -// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t -fcrash-diagnostics=all 2>&1 \ +// RUN: echo "-nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t" \ +// RUN: | sed -e 's/\\/\\\\/g' > %t.rsp + +// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all 2>&1 \ +// RUN: | FileCheck %s + +// Test that the reproducer can still be created even when the input source cannot be preprocessed +// again, like when reading from stdin. +// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all 2>&1 < %s \ // RUN: | FileCheck %s // check that we still get lld's output // CHECK: error: undefined symbol: {{_?}}a // CHECK: Preprocessed source(s) and associated run script(s) are located at: -// CHECK-NEXT: note: diagnostic msg: {{.*}}lld-repro-{{.*}}.c // CHECK-NEXT: note: diagnostic msg: {{.*}}linker-crash-{{.*}}.tar -// CHECK-NEXT: note: diagnostic msg: {{.*}}lld-repro-{{.*}}.sh // CHECK-NEXT: note: diagnostic msg: // CHECK: ******************** -// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t -fcrash-diagnostics=compiler 2>&1 \ +// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler 2>&1 \ // RUN: | FileCheck %s --check-prefix=NO-LINKER -// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t 2>&1 \ +// RUN: not %clang %s @%t.rsp 2>&1 \ // RUN: | FileCheck %s --check-prefix=NO-LINKER // NO-LINKER-NOT: Preprocessed source(s) and associated run script(s) are located at: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits