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: http://review.tizen.org/git/?a=commitdiff_plain;h=332a5e526e6d22bc9e628adb91cc7b2ece188001;p=platform%2Fupstream%2Fllvm.git 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). llvm-svn: 211411 --- diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h index 3493e4f..c1c0f43 100644 --- a/clang/include/clang/Driver/Compilation.h +++ b/clang/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/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp index 4baa195..8244875 100644 --- a/clang/lib/Driver/Compilation.cpp +++ b/clang/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/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 34c48d4..3740c5a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/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/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index d2b72a0..6117364 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/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/clang/test/Driver/crash-report.c b/clang/test/Driver/crash-report.c index 59ce8f7..c9e7866 100644 --- a/clang/test/Driver/crash-report.c +++ b/clang/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