From: Richard Smith Date: Tue, 25 Dec 2012 21:56:27 +0000 (+0000) Subject: Produce an actual error before attempting to attach notes to it when bailing out X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a57b3b4fea1c962678972af8fc74e121ff8b296d;p=clang Produce an actual error before attempting to attach notes to it when bailing out due to FORCE_CLANG_DIAGNOSTICS_CRASH=1. Also add a test for that env var. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171074 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index a8b21173db..5fec06dc88 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -67,6 +67,8 @@ def err_drv_command_failed : Error< "%0 command failed with exit code %1 (use -v to see invocation)">; def err_drv_command_signalled : Error< "%0 command failed due to signal (use -v to see invocation)">; +def err_drv_force_crash : Error< + "failing because environment variable '%0' is set">; def err_drv_invalid_mfloat_abi : Error< "invalid float ABI '%0'">; def err_drv_invalid_libcxx_deployment : Error< diff --git a/test/Driver/crash-report.c b/test/Driver/crash-report.c index bfcd5732b3..975e9a8a71 100644 --- a/test/Driver/crash-report.c +++ b/test/Driver/crash-report.c @@ -9,6 +9,8 @@ // RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s // REQUIRES: crash-recovery +// RUN: env FORCE_CLANG_DIAGNOSTICS_CRASH=1 %clang -fsyntax-only -x c /dev/null 2>&1 | FileCheck %s + #pragma clang __debug parser_crash // CHECK: Preprocessed source(s) and associated run script(s) are located at: // CHECK-NEXT: note: diagnostic msg: {{.*}}.c diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index 353d06fb14..de2b899bfa 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -16,6 +16,7 @@ #include "clang/Driver/ArgList.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/OptTable.h" #include "clang/Driver/Option.h" #include "clang/Driver/Options.h" @@ -470,8 +471,10 @@ int main(int argc_, const char **argv_) { Res = TheDriver.ExecuteCompilation(*C, FailingCommand); // Force a crash to test the diagnostics. - if(::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH")) - Res = -1; + if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH")) { + Diags.Report(diag::err_drv_force_crash) << "FORCE_CLANG_DIAGNOSTICS_CRASH"; + Res = -1; + } // If result status is < 0, then the driver command signalled an error. // If result status is 70, then the driver command reported a fatal error.