xur created this revision.
xur added reviewers: tejohnson, jeroen.dobbelaere.

This patch fixes PR44896.

For IR input files, option fdiscard-value-names should be ignored as we need 
named values in loadModule().
Commit 60d3947922 
<https://reviews.llvm.org/rG60d39479221d6bc09060f7816bcd7c54eb286603> sets this 
option after loadModule() where valued names already created. This creates an 
inconsistent state in setNameImpl() that leads to a seg fault.
This patch forces fdiscard-value-names to be false for IR input files.


https://reviews.llvm.org/D74878

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/PR44896.ll


Index: clang/test/CodeGen/PR44896.ll
===================================================================
--- /dev/null
+++ clang/test/CodeGen/PR44896.ll
@@ -0,0 +1,7 @@
+; RUN: %clang_cc1 -triple x86_64-unknown-unknown -O3 -S -emit-llvm %s 
-discard-value-names -o -
+; PR 44896
+
+define linkonce i8* @b(i8* %a) {
+  ret i8* %a
+}
+
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1146,6 +1146,9 @@
                            CI.getTargetOpts(), CI.getLangOpts(),
                            CI.getFrontendOpts().ShowTimers,
                            std::move(LinkModules), *VMContext, nullptr);
+    // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
+    // true here because the valued names are needed for reading textual IR.
+    Ctx.setDiscardValueNames(false);
     Ctx.setDiagnosticHandler(
         std::make_unique<ClangDiagnosticHandler>(CodeGenOpts, &Result));
 


Index: clang/test/CodeGen/PR44896.ll
===================================================================
--- /dev/null
+++ clang/test/CodeGen/PR44896.ll
@@ -0,0 +1,7 @@
+; RUN: %clang_cc1 -triple x86_64-unknown-unknown -O3 -S -emit-llvm %s -discard-value-names -o -
+; PR 44896
+
+define linkonce i8* @b(i8* %a) {
+  ret i8* %a
+}
+
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1146,6 +1146,9 @@
                            CI.getTargetOpts(), CI.getLangOpts(),
                            CI.getFrontendOpts().ShowTimers,
                            std::move(LinkModules), *VMContext, nullptr);
+    // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
+    // true here because the valued names are needed for reading textual IR.
+    Ctx.setDiscardValueNames(false);
     Ctx.setDiagnosticHandler(
         std::make_unique<ClangDiagnosticHandler>(CodeGenOpts, &Result));
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to