Skip to content

Commit

Permalink
[clang] Put original flags on 'Driver args:' crash report line
Browse files Browse the repository at this point in the history
We used to put the canonical spelling of flags after alias processing
on that line. For clang-cl in particular, that meant that we put flags
on that line that the clang-cl driver doesn't even accept, and the
"Driver args:" line wasn't usable.

Differential Revision: https://reviews.llvm.org/D110458
  • Loading branch information
nico committed Sep 27, 2021
1 parent 1455b55 commit 63bb2d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clang/lib/Driver/Driver.cpp
Expand Up @@ -1216,8 +1216,14 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {

static void printArgList(raw_ostream &OS, const llvm::opt::ArgList &Args) {
llvm::opt::ArgStringList ASL;
for (const auto *A : Args)
for (const auto *A : Args) {
// Use user's original spelling of flags. For example, use
// `/source-charset:utf-8` instead of `-finput-charset=utf-8` if the user
// wrote the former.
while (A->getAlias())
A = A->getAlias();
A->render(Args, ASL);
}

for (auto I = ASL.begin(), E = ASL.end(); I != E; ++I) {
if (I != ASL.begin())
Expand Down
24 changes: 24 additions & 0 deletions clang/test/Driver/crash-report-clang-cl.c
@@ -0,0 +1,24 @@
// RUN: rm -rf %t
// RUN: mkdir %t

// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1 \
// RUN: not %clang_cl -fsyntax-only /Brepro /source-charset:utf-8 \
// RUN: -- %s 2>&1 | FileCheck %s
// RUN: cat %t/crash-report-*.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:
// CHECK-NEXT: note: diagnostic msg: {{.*}}crash-report-clang-cl-{{.*}}.c
// 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.c"
// CHECKSH: "crash-report-{{[^ ]*}}.c"

0 comments on commit 63bb2d5

Please sign in to comment.