Skip to content

Commit 78ed64d

Browse files
committed
[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
1 parent 74d8628 commit 78ed64d

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,11 @@ bool Driver::getCrashDiagnosticFile(StringRef ReproCrashFilename,
15271527
return false;
15281528
}
15291529

1530+
static const char BugReporMsg[] =
1531+
"\n********************\n\n"
1532+
"PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n"
1533+
"Preprocessed source(s) and associated run script(s) are located at:";
1534+
15301535
// When clang crashes, produce diagnostic information including the fully
15311536
// preprocessed source file(s). Request that the developer attach the
15321537
// diagnostic information to a bug report.
@@ -1582,6 +1587,29 @@ void Driver::generateCompilationDiagnostics(
15821587
// Suppress tool output.
15831588
C.initCompilationForDiagnostics();
15841589

1590+
// If lld failed, rerun it again with --reproduce.
1591+
if (IsLLD) {
1592+
const char *TmpName = CreateTempFile(C, "linker-crash", "tar");
1593+
Command NewLLDInvocation = Cmd;
1594+
llvm::opt::ArgStringList ArgList = NewLLDInvocation.getArguments();
1595+
StringRef ReproduceOption =
1596+
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment()
1597+
? "/reproduce:"
1598+
: "--reproduce=";
1599+
ArgList.push_back(Saver.save(Twine(ReproduceOption) + TmpName).data());
1600+
NewLLDInvocation.replaceArguments(std::move(ArgList));
1601+
1602+
// Redirect stdout/stderr to /dev/null.
1603+
NewLLDInvocation.Execute({None, {""}, {""}}, nullptr, nullptr);
1604+
Diag(clang::diag::note_drv_command_failed_diag_msg) << BugReporMsg;
1605+
Diag(clang::diag::note_drv_command_failed_diag_msg) << TmpName;
1606+
Diag(clang::diag::note_drv_command_failed_diag_msg)
1607+
<< "\n\n********************";
1608+
if (Report)
1609+
Report->TemporaryFiles.push_back(TmpName);
1610+
return;
1611+
}
1612+
15851613
// Construct the list of inputs.
15861614
InputList Inputs;
15871615
BuildInputs(C.getDefaultToolChain(), C.getArgs(), Inputs);
@@ -1659,33 +1687,14 @@ void Driver::generateCompilationDiagnostics(
16591687
return;
16601688
}
16611689

1662-
// If lld failed, rerun it again with --reproduce.
1663-
if (IsLLD) {
1664-
const char *TmpName = CreateTempFile(C, "linker-crash", "tar");
1665-
Command NewLLDInvocation = Cmd;
1666-
llvm::opt::ArgStringList ArgList = NewLLDInvocation.getArguments();
1667-
StringRef ReproduceOption =
1668-
C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment()
1669-
? "/reproduce:"
1670-
: "--reproduce=";
1671-
ArgList.push_back(Saver.save(Twine(ReproduceOption) + TmpName).data());
1672-
NewLLDInvocation.replaceArguments(std::move(ArgList));
1673-
1674-
// Redirect stdout/stderr to /dev/null.
1675-
NewLLDInvocation.Execute({None, {""}, {""}}, nullptr, nullptr);
1676-
}
1677-
16781690
const ArgStringList &TempFiles = C.getTempFiles();
16791691
if (TempFiles.empty()) {
16801692
Diag(clang::diag::note_drv_command_failed_diag_msg)
16811693
<< "Error generating preprocessed source(s).";
16821694
return;
16831695
}
16841696

1685-
Diag(clang::diag::note_drv_command_failed_diag_msg)
1686-
<< "\n********************\n\n"
1687-
"PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n"
1688-
"Preprocessed source(s) and associated run script(s) are located at:";
1697+
Diag(clang::diag::note_drv_command_failed_diag_msg) << BugReporMsg;
16891698

16901699
SmallString<128> VFS;
16911700
SmallString<128> ReproCrashFilename;

clang/test/Driver/lld-repro.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
// REQUIRES: lld
22
// UNSUPPORTED: ps4, ps5
33

4-
// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t -fcrash-diagnostics=all 2>&1 \
4+
// RUN: echo "-nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t" \
5+
// RUN: | sed -e 's/\\/\\\\/g' > %t.rsp
6+
7+
// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=all 2>&1 \
8+
// RUN: | FileCheck %s
9+
10+
// Test that the reproducer can still be created even when the input source cannot be preprocessed
11+
// again, like when reading from stdin.
12+
// RUN: not %clang -x c - @%t.rsp -fcrash-diagnostics=all 2>&1 < %s \
513
// RUN: | FileCheck %s
614

715
// check that we still get lld's output
816
// CHECK: error: undefined symbol: {{_?}}a
917

1018
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
11-
// CHECK-NEXT: note: diagnostic msg: {{.*}}lld-repro-{{.*}}.c
1219
// CHECK-NEXT: note: diagnostic msg: {{.*}}linker-crash-{{.*}}.tar
13-
// CHECK-NEXT: note: diagnostic msg: {{.*}}lld-repro-{{.*}}.sh
1420
// CHECK-NEXT: note: diagnostic msg:
1521
// CHECK: ********************
1622

17-
// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t -fcrash-diagnostics=compiler 2>&1 \
23+
// RUN: not %clang %s @%t.rsp -fcrash-diagnostics=compiler 2>&1 \
1824
// RUN: | FileCheck %s --check-prefix=NO-LINKER
19-
// RUN: not %clang %s -nostartfiles -nostdlib -fuse-ld=lld -gen-reproducer=error -fcrash-diagnostics-dir=%t 2>&1 \
25+
// RUN: not %clang %s @%t.rsp 2>&1 \
2026
// RUN: | FileCheck %s --check-prefix=NO-LINKER
2127

2228
// NO-LINKER-NOT: Preprocessed source(s) and associated run script(s) are located at:

0 commit comments

Comments
 (0)