From: Justin Bogner Date: Fri, 20 Jun 2014 22:16:00 +0000 (+0000) Subject: Driver: Record that we're in crashdump and push flags to ConstructJob X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7c5ec1c87bda9a98af5a168933be2dd6c56503f;p=clang Driver: Record that we're in crashdump and push flags to ConstructJob It's more flexible and arguably better layering to set flags to modify compiling for diagnostics in the CC1 job themselves, rather than tweaking the driver flags and letting them propagate. There is one visible change this causes: crash report files will now get preprocessed names (.i and friends). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211411 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h index 3493e4f150..c1c0f4326d 100644 --- a/include/clang/Driver/Compilation.h +++ b/include/clang/Driver/Compilation.h @@ -69,6 +69,9 @@ class Compilation { /// Redirection for stdout, stderr, etc. const StringRef **Redirects; + /// Whether we're compiling for diagnostic purposes. + bool ForDiagnostics; + public: Compilation(const Driver &D, const ToolChain &DefaultToolChain, llvm::opt::InputArgList *Args, @@ -173,6 +176,9 @@ public: /// so compilation can be reexecuted to generate additional diagnostic /// information (e.g., preprocessed source(s)). void initCompilationForDiagnostics(); + + /// Return true if we're compiling for diagnostics. + bool isForDiagnostics() { return ForDiagnostics; } }; } // end namespace driver diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 4baa195d3b..8244875c7b 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -26,9 +26,9 @@ using namespace llvm::opt; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, InputArgList *_Args, DerivedArgList *_TranslatedArgs) - : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), - TranslatedArgs(_TranslatedArgs), Redirects(nullptr) { -} + : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), + TranslatedArgs(_TranslatedArgs), Redirects(nullptr), + ForDiagnostics(false) {} Compilation::~Compilation() { delete TranslatedArgs; @@ -211,6 +211,8 @@ void Compilation::ExecuteJob(const Job &J, } void Compilation::initCompilationForDiagnostics() { + ForDiagnostics = true; + // Free actions and jobs. DeleteContainerPointers(Actions); Jobs.clear(); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 34c48d4e38..3740c5a0fc 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -419,8 +419,6 @@ void Driver::generateCompilationDiagnostics(Compilation &C, // Suppress driver output and emit preprocessor output to temp file. Mode = CPPMode; CCGenDiagnostics = true; - C.getArgs().AddFlagArg(nullptr, - Opts->getOption(options::OPT_frewrite_includes)); // Save the original job command(s). std::string Cmd; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d2b72a0977..61173643d4 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3339,10 +3339,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Args.getLastArg(options::OPT_fapple_kext)) CmdArgs.push_back("-fapple-kext"); - if (Args.hasFlag(options::OPT_frewrite_includes, - options::OPT_fno_rewrite_includes, false)) - CmdArgs.push_back("-frewrite-includes"); - Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits); @@ -4037,6 +4033,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } #endif + if (Args.hasFlag(options::OPT_frewrite_includes, + options::OPT_fno_rewrite_includes, false) || + C.isForDiagnostics()) + CmdArgs.push_back("-frewrite-includes"); + // Only allow -traditional or -traditional-cpp outside in preprocessing modes. if (Arg *A = Args.getLastArg(options::OPT_traditional, options::OPT_traditional_cpp)) { diff --git a/test/Driver/crash-report.c b/test/Driver/crash-report.c index 59ce8f76a3..c9e7866662 100644 --- a/test/Driver/crash-report.c +++ b/test/Driver/crash-report.c @@ -7,11 +7,11 @@ // RUN: -Xclang -internal-isystem -Xclang /tmp/ \ // RUN: -Xclang -internal-externc-isystem -Xclang /tmp/ \ // RUN: -DFOO=BAR 2>&1 | FileCheck %s -// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s +// RUN: cat %t/crash-report-*.i | FileCheck --check-prefix=CHECKSRC %s // RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s // REQUIRES: crash-recovery -// because of the glob (*.c, *.sh) +// because of the glob (*.i, *.sh) // REQUIRES: shell // RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH=1 %clang -fsyntax-only -x c /dev/null -lstdc++ 2>&1 | FileCheck %s @@ -21,7 +21,7 @@ #pragma clang __debug parser_crash // CHECK: Preprocessed source(s) and associated run script(s) are located at: -// CHECK-NEXT: note: diagnostic msg: {{.*}}.c +// CHECK-NEXT: note: diagnostic msg: {{.*}}.i FOO // CHECKSRC: FOO // CHECKSH: -cc1