[PATCH] D30898: Add new -fverbose-asm that enables source interleaving

Roger Ferrer Ibanez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 09:28:22 PDT 2017


rogfer01 created this revision.

This is the clang side of the RFC in http://lists.llvm.org/pipermail/cfe-dev/2017-February/052549.html

Note that in contrast to the original suggestion `-fsource-asm` here we use the preferred `-fverbose-asm`. Basically explicitly saying `-fverbose-asm` in the command line enables a minimum amount of debugging, so in AsmPrinter we can use it to print the source code.

This patch introduces a `-masm-source` flag for cc1 that maps to the AsmSource value in the llvm code generation.


https://reviews.llvm.org/D30898

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -560,6 +560,7 @@
       Args.hasFlag(OPT_fcoverage_mapping, OPT_fno_coverage_mapping, false);
   Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
   Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
+  Opts.AsmSource = getLastArgIntValue(Args, OPT_masm_source, 0, Diags);
   Opts.PreserveAsmComments = !Args.hasArg(OPT_fno_preserve_as_comments);
   Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
   Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2748,6 +2748,20 @@
     CmdArgs.push_back("-split-dwarf=Enable");
   }
 
+  // If -fverbose-asm explicitly appears enable at least DebugLineTablesOnly
+  // but remember that no debug info was requested, to avoid cluttering
+  // assembler output with debug directives.
+  if (Args.hasArg(options::OPT_fverbose_asm)) {
+    CmdArgs.push_back("-masm-source");
+    if (DebugInfoKind == codegenoptions::NoDebugInfo) {
+      // FIXME: Check whether LimitedDebugInfo will give us line information,
+      // otherwise we should be overriding it as well.
+      DebugInfoKind = codegenoptions::DebugLineTablesOnly;
+      CmdArgs.push_back("1");
+    } else
+      CmdArgs.push_back("2");
+  }
+
   // After we've dealt with all combinations of things that could
   // make DebugInfoKind be other than None or DebugLineTablesOnly,
   // figure out if we need to "upgrade" it to standalone debug info.
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -604,6 +604,7 @@
   Options.MCOptions.MCPIECopyRelocations = CodeGenOpts.PIECopyRelocations;
   Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
   Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
+  Options.MCOptions.AsmSource = CodeGenOpts.AsmSource;
   Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
   Options.MCOptions.ABIName = TargetOpts.ABI;
   for (const auto &Entry : HSOpts.UserEntries)
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -32,6 +32,7 @@
 CODEGENOPT(CompressDebugSections, 1, 0) ///< -Wa,-compress-debug-sections
 CODEGENOPT(RelaxELFRelocations, 1, 0) ///< -Wa,--mrelax-relocations
 CODEGENOPT(AsmVerbose        , 1, 0) ///< -dA, -fverbose-asm.
+CODEGENOPT(AsmSource         , 2, 0) ///< -fverbose-asm.
 CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
 CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
 CODEGENOPT(Autolink          , 1, 1) ///< -fno-autolink
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -225,6 +225,8 @@
   HelpText<"Turn off struct-path aware Type Based Alias Analysis">;
 def masm_verbose : Flag<["-"], "masm-verbose">,
   HelpText<"Generate verbose assembly output">;
+def masm_source : Separate<["-"], "masm-source">,
+  HelpText<"Annotate assembly output with source code lines.">;
 def mcode_model : Separate<["-"], "mcode-model">,
   HelpText<"The code model to use">;
 def mdebug_pass : Separate<["-"], "mdebug-pass">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30898.91574.patch
Type: text/x-patch
Size: 3756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170313/8ee7bd9a/attachment.bin>


More information about the cfe-commits mailing list