]> granicus.if.org Git - clang/commitdiff
Add support for passing the main file name down to the assembler
authorEric Christopher <echristo@gmail.com>
Tue, 18 Dec 2012 00:31:10 +0000 (00:31 +0000)
committerEric Christopher <echristo@gmail.com>
Tue, 18 Dec 2012 00:31:10 +0000 (00:31 +0000)
for location information.

Part of PR14624

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170391 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1AsOptions.td
lib/Driver/Tools.cpp
lib/Driver/Tools.h
test/Driver/debug-main-file.S [new file with mode: 0644]
tools/driver/cc1as_main.cpp

index 620d7215063f1d05e273ea79e68fe9f13db13425..6a91e0cf8c1441251a5b7951e8fd5aa03b9d0994 100644 (file)
@@ -37,6 +37,8 @@ def L : Flag<["-"], "L">,
   HelpText<"Save temporary labels in the symbol table. "
            "Note this may change .s semantics, it should almost never be used "
            "on compiler generated code!">;
+def main_file_name : Separate<["-"], "main-file-name">,
+  HelpText<"Main file name to use for debug info">;
 
 //===----------------------------------------------------------------------===//
 // Frontend Options
index bbc3cccef32712ab0c9bdec7d48dc8ed7cde32d6..eec3974c8dcbbb7a0c8220279d777d955a9f3b8a 100644 (file)
@@ -1388,12 +1388,12 @@ static bool ShouldDisableCFI(const ArgList &Args,
     // The native darwin assembler doesn't support cfi directives, so
     // we disable them if we think the .s file will be passed to it.
     Default = Args.hasFlag(options::OPT_integrated_as,
-                          options::OPT_no_integrated_as,
-                          TC.IsIntegratedAssemblerDefault());
+                           options::OPT_no_integrated_as,
+                           TC.IsIntegratedAssemblerDefault());
   }
   return !Args.hasFlag(options::OPT_fdwarf2_cfi_asm,
-                      options::OPT_fno_dwarf2_cfi_asm,
-                      Default);
+                       options::OPT_fno_dwarf2_cfi_asm,
+                       Default);
 }
 
 static bool ShouldDisableDwarfDirectory(const ArgList &Args,
@@ -3278,6 +3278,11 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back("-filetype");
   CmdArgs.push_back("obj");
 
+  // Set the main file name, so that debug info works even with
+  // -save-temps or preprocessed assembly.
+  CmdArgs.push_back("-main-file-name");
+  CmdArgs.push_back(Clang::getBaseInputName(Args, Inputs));
+
   if (UseRelaxAll(C, Args))
     CmdArgs.push_back("-relax-all");
 
@@ -4367,10 +4372,10 @@ void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
 }
 
 void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
-                                      const InputInfo &Output,
-                                      const InputInfoList &Inputs,
-                                      const ArgList &Args,
-                                      const char *LinkingOutput) const {
+                                       const InputInfo &Output,
+                                       const InputInfoList &Inputs,
+                                       const ArgList &Args,
+                                       const char *LinkingOutput) const {
   ArgStringList CmdArgs;
   CmdArgs.push_back("--verify");
   CmdArgs.push_back("--debug-info");
@@ -5751,7 +5756,7 @@ void minix::Link::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-lCompilerRT-Generic");
     CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
     CmdArgs.push_back(
-        Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
+         Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
   }
 
   const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
index be38edb034a223b18502a063b9795438875d577d..dcfd3114ddbba08ab4aa1a7614f6f03945bb1d1b 100644 (file)
@@ -30,6 +30,7 @@ namespace tools {
 
   /// \brief Clang compiler tool.
   class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
+  public:
     static const char *getBaseInputName(const ArgList &Args,
                                         const InputInfoList &Inputs);
     static const char *getBaseInputStem(const ArgList &Args,
@@ -37,6 +38,7 @@ namespace tools {
     static const char *getDependencyFileName(const ArgList &Args,
                                              const InputInfoList &Inputs);
 
+  private:
     void AddPreprocessingOptions(Compilation &C,
                                  const Driver &D,
                                  const ArgList &Args,
@@ -286,15 +288,15 @@ namespace darwin {
   class LLVM_LIBRARY_VISIBILITY VerifyDebug : public DarwinTool  {
   public:
     VerifyDebug(const ToolChain &TC) : DarwinTool("darwin::VerifyDebug",
-                                                 "dwarfdump", TC) {}
+                                                  "dwarfdump", TC) {}
 
     virtual bool hasIntegratedCPP() const { return false; }
 
     virtual void ConstructJob(Compilation &C, const JobAction &JA,
-                             const InputInfo &Output,
-                             const InputInfoList &Inputs,
-                             const ArgList &TCArgs,
-                             const char *LinkingOutput) const;
+                              const InputInfo &Output,
+                              const InputInfoList &Inputs,
+                              const ArgList &TCArgs,
+                              const char *LinkingOutput) const;
   };
 
 }
diff --git a/test/Driver/debug-main-file.S b/test/Driver/debug-main-file.S
new file mode 100644 (file)
index 0000000..8c154a3
--- /dev/null
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// RUN: %clang -### -c -save-temps -integrated-as -g %s 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK: main-file-name
+
+#ifdef(1)
+foo:
+        nop
+        nop
+        nop
+#endif
index 73be56c2b4cb5696bf14132afc0ef71b46604fa4..f01d97d1c5b2a81b197d65c25d692eafd26c11d1 100644 (file)
@@ -84,6 +84,7 @@ struct AssemblerInvocation {
   unsigned GenDwarfForAssembly : 1;
   std::string DwarfDebugFlags;
   std::string DebugCompilationDir;
+  std::string MainFileName;
 
   /// @}
   /// @name Frontend Options
@@ -183,6 +184,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.GenDwarfForAssembly = Args->hasArg(OPT_g);
   Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags);
   Opts.DebugCompilationDir = Args->getLastArgValue(OPT_fdebug_compilation_dir);
+  Opts.MainFileName = Args->getLastArgValue(OPT_main_file_name);
 
   // Frontend Options
   if (Args->hasArg(OPT_INPUT)) {
@@ -309,6 +311,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
     Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
   if (!Opts.DebugCompilationDir.empty())
     Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  if (!Opts.MainFileName.empty())
+    Ctx.setMainFileName(StringRef(Opts.MainFileName));
 
   // Build up the feature string from the target feature list.
   std::string FS;