]> granicus.if.org Git - clang/commitdiff
Driver: Record that we're in crashdump and push flags to ConstructJob
authorJustin Bogner <mail@justinbogner.com>
Fri, 20 Jun 2014 22:16:00 +0000 (22:16 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 20 Jun 2014 22:16:00 +0000 (22:16 +0000)
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

include/clang/Driver/Compilation.h
lib/Driver/Compilation.cpp
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp
test/Driver/crash-report.c

index 3493e4f1509b4b63d9e8ef548322c626f765fc66..c1c0f4326d76d67f808b1fb671eb87af7ab37aec 100644 (file)
@@ -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
index 4baa195d3b81280e546be888ed67fb81ab0a39a7..8244875c7be91cda9df041b71dd11c838ed6e9a2 100644 (file)
@@ -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();
index 34c48d4e38821b058c8282f7bde554f775e34f88..3740c5a0fc8ce97a9a4ab8201435f888746794ea 100644 (file)
@@ -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;
index d2b72a09773ec301c2bf8d043cf0919128422968..61173643d4b22466863d8c06acb8bd961da10a9a 100644 (file)
@@ -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)) {
index 59ce8f76a3ec2bc4fd995464d627bfaf90d39ff1..c9e7866662828dc9f726bd117552f2e004d9cb5e 100644 (file)
@@ -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