Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Make crash reproducer work with clang-cl
When clang crashes, it writes a standalone source file and shell script to reproduce the crash. The Driver used to set `Mode = CPPMode` in generateCompilationDiagnostics() to force preprocessing mode. This has the side effect of making IsCLMode() return false, which in turn meant Clang::AddClangCLArgs() didn't get called when creating the standalone source file, which meant the stand-alone file was preprocessed with the gcc driver's defaults In particular, exceptions default to on with the gcc driver, but to off with the cl driver. The .sh script did use the original command line, so in the reproducer for a clang-cl crash, the standalone source file could contain exception-using code after preprocessing that the compiler invocation in the shell script would then complain about. This patch removes the `Mode = CPPMode;` line and instead additionally checks for `CCGenDiagnostics` in most places that check `CCCIsCPP(). This also matches the strategy Clang::ConstructJob() uses to add -frewrite-includes for creating the standalone source file for a crash report. Fixes PR52007. Differential Revision: https://reviews.llvm.org/D110783
- Loading branch information
Showing
4 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
|
||
// RUN: not %clang_cl -fsyntax-only /Brepro /source-charset:utf-8 \ | ||
// RUN: -fcrash-diagnostics-dir=%t -- %s 2>&1 | FileCheck %s | ||
// RUN: cat %t/crash-report-clang-cl-*.cpp | FileCheck --check-prefix=CHECKSRC %s | ||
// RUN: cat %t/crash-report-clang-cl-*.sh | FileCheck --check-prefix=CHECKSH %s | ||
|
||
// REQUIRES: crash-recovery | ||
|
||
#pragma clang __debug crash | ||
|
||
// CHECK: Preprocessed source(s) and associated run script(s) are located at: | ||
|
||
// __has_feature(cxx_exceptions) is default-off in the cl-compatible driver. | ||
FOO | ||
#if __has_feature(cxx_exceptions) | ||
int a = 1; | ||
#else | ||
int a = 0; | ||
#endif | ||
// CHECKSRC: {{^}}FOO | ||
// CHECKSRC-NEXT: {{^}}#if 0 /* disabled by -frewrite-includes */ | ||
// CHECKSRC-NEXT: {{^}}#if __has_feature(cxx_exceptions) | ||
// CHECKSRC-NEXT: {{^}}#endif | ||
// CHECKSRC-NEXT: {{^}}#endif /* disabled by -frewrite-includes */ | ||
// CHECKSRC-NEXT: {{^}}#if 0 /* evaluated by -frewrite-includes */ | ||
// CHECKSRC-NEXT: {{^}}# | ||
// CHECKSRC-NEXT: {{^}}int a = 1; | ||
// CHECKSRC-NEXT: {{^}}#else | ||
// CHECKSRC-NEXT: {{^}}# | ||
// CHECKSRC-NEXT: {{^}}int a = 0; | ||
// CHECKSRC-NEXT: {{^}}#endif | ||
|
||
// CHECK-NEXT: note: diagnostic msg: {{.*}}crash-report-clang-cl-{{.*}}.cpp | ||
// CHECKSH: # Crash reproducer | ||
// CHECKSH-NEXT: # Driver args: {{.*}}"-fsyntax-only" | ||
// CHECKSH-SAME: /Brepro | ||
// CHECKSH-SAME: /source-charset:utf-8 | ||
// CHECKSH-NOT: -mno-incremental-linker-compatible | ||
// CHECKSH-NOT: -finput-charset=utf-8 | ||
// CHECKSH-NEXT: # Original command: {{.*$}} | ||
// CHECKSH-NEXT: "-cc1" | ||
// CHECKSH: "-main-file-name" "crash-report-clang-cl.cpp" | ||
// CHECKSH: "crash-report-{{[^ ]*}}.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters