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

Zhizhou Yang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 18:08:52 PDT 2017


zhizhouy updated this revision to Diff 92410.
zhizhouy added a comment.

Re-implemented the the patch: reusing -grecord-gcc-switches from gcc instead of passing arguments to DiagnosticsEngine.

If user specify the -grecord-gcc-switches in command line, Clang will start to record it in Driver, and create a CC1Option of "-record-cmd-opts" and record it in CodeGenOptions.

Producer will be updated directly from the CodeGenOptions.


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)) {
+    std::string CmdLineOpts = "";
+    for (const auto *Arg : Args) CmdLineOpts += Arg->getAsString(Args) + " ";
+    CmdLineOpts.pop_back();
+    CmdArgs.push_back(Args.MakeArgString("-record-cmd-opts=" +
+                                         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.92410.patch
Type: text/x-patch
Size: 3249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170321/9054d634/attachment.bin>


More information about the cfe-commits mailing list