[PATCH] D74871: Fix interaction between -fdiscard-value-names and LLVM Bitcode

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 19 13:48:51 PST 2020


serge-sans-paille created this revision.
serge-sans-paille added reviewers: EricWF, mehdi_amini.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without that patch, the test case associated to this patch segfaults in Release mode. This also makes the llvm-test-suite build fails, including in 10.0.0 rc2.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74871

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp


Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3603,6 +3603,11 @@
     LangOpts.PIE = Args.hasArg(OPT_pic_is_pie);
     parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
                         Diags, LangOpts.Sanitize);
+    // Cannot discard value names when processing llvm-ir, because IR loading
+    // is conservative wrt. names.
+    if (Res.getCodeGenOpts().DiscardValueNames) {
+      Res.getCodeGenOpts().DiscardValueNames = false;
+    }
   } else {
     // Other LangOpts are only initialized when the input is not AST or LLVM IR.
     // FIXME: Should we really be calling this for an Language::Asm input?
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4332,8 +4332,15 @@
 
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
-                   options::OPT_fno_discard_value_names, !IsAssertBuild))
+                   options::OPT_fno_discard_value_names, !IsAssertBuild)) {
+    if (std::any_of(Inputs.begin(), Inputs.end(),
+                    [](const clang::driver::InputInfo &II) {
+                      return types::isLLVMIR(II.getType());
+                    })) {
+      D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
+    }
     CmdArgs.push_back("-discard-value-names");
+  }
 
   // Set the main file name, so that debug info works even with
   // -save-temps.
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -271,6 +271,9 @@
   InGroup<UnsupportedTargetOpt>;
 def warn_c_kext : Warning<
   "ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
+def warn_ignoring_fdiscard_for_bitcode : Warning<
+  "ignoring -fdiscard-value-names for LLVM Bitcode">,
+  InGroup<UnusedCommandLineArgument>;
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused%select{ when '%3' is present|}2">,
   InGroup<UnusedCommandLineArgument>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74871.245510.patch
Type: text/x-patch
Size: 2396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200219/408ae37d/attachment-0001.bin>


More information about the cfe-commits mailing list