[PATCH] D30760: Record command lines in objects built by clang

Zhizhou Yang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 21 14:31:42 PDT 2017


zhizhouy updated this revision to Diff 92546.
zhizhouy marked 3 inline comments as done.
zhizhouy edited the summary of this revision.
zhizhouy added a reviewer: dblaikie.
zhizhouy added a comment.
Herald added a subscriber: mehdi_amini.

Fixed George's comments.

Still need to create a test for this diff.


https://reviews.llvm.org/D30760

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


Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -529,6 +529,7 @@
   Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
   Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCmdOpts = Args.getLastArgValue(OPT_record_cmd_opts_EQ);
   Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2720,7 +2720,16 @@
     DwarfVersion = getToolChain().GetDefaultDwarfVersion();
   }
 
-  // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now.
+  // Use -grecord-gcc-switches to record command line options from Driver.
+  if (Args.hasArg(options::OPT_grecord_gcc_switches)) {
+    SmallString<256> CmdLineOpts("-record-cmd-opts=");
+    for (const auto *Arg : Args)
+      CmdLineOpts += Arg->getAsString(Args) + " ";
+    CmdLineOpts.pop_back();
+    CmdArgs.push_back(Args.MakeArgStringRef(CmdLineOpts));
+  }
+
+  // We ignore flags -gstrict-dwarf for now.
   Args.ClaimAllArgs(options::OPT_g_flags_Group);
 
   // Column info is included by default for everything except PS4 and CodeView.
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -503,7 +503,10 @@
     LangTag = llvm::dwarf::DW_LANG_C89;
   }
 
+  // Producer records current clang version and the command line options from
+  // Driver.
   std::string Producer = getClangFullVersion();
+  Producer += " " + CGM.getCodeGenOpts().RecordCmdOpts;
 
   // Figure out which version of the ObjC runtime we have.
   unsigned RuntimeVers = 0;
Index: include/clang/Frontend/CodeGenOptions.h
===================================================================
--- include/clang/Frontend/CodeGenOptions.h
+++ include/clang/Frontend/CodeGenOptions.h
@@ -119,6 +119,9 @@
   /// non-empty.
   std::string DwarfDebugFlags;
 
+  /// The string of command line options from Driver.
+  std::string RecordCmdOpts;
+
   std::map<std::string, std::string> DebugPrefixMap;
 
   /// The ABI to use for passing floating point arguments.
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -144,6 +144,7 @@
   HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
+def record_cmd_opts_EQ : Joined<["-"], "record-cmd-opts=">;
 def mno_exec_stack : Flag<["-"], "mnoexecstack">,
   HelpText<"Mark the file as not needing an executable stack">;
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30760.92546.patch
Type: text/x-patch
Size: 3216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170321/53897964/attachment-0001.bin>


More information about the cfe-commits mailing list