]> granicus.if.org Git - clang/commitdiff
[LTO] Fix -save-temps with LTO and unnamed globals.
authorEli Friedman <efriedma@codeaurora.org>
Fri, 24 Aug 2018 19:31:52 +0000 (19:31 +0000)
committerEli Friedman <efriedma@codeaurora.org>
Fri, 24 Aug 2018 19:31:52 +0000 (19:31 +0000)
If all LLVM passes are disabled, we can't emit a summary because there
could be unnamed globals in the IR.

Differential Revision: https://reviews.llvm.org/D51198

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340640 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/BackendUtil.cpp
test/CodeGen/summary-index-unnamed-global.ll [new file with mode: 0644]

index 6da284e78c3cbb2d58daaf9372a59e62de647662..3fd01a73251dc6c661040f62d0278e8fecfa97b8 100644 (file)
@@ -783,7 +783,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
     break;
 
   case Backend_EmitBC:
-    if (CodeGenOpts.PrepareForThinLTO) {
+    if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
       if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
         ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
         if (!ThinLinkOS)
@@ -796,6 +796,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
       // targets
       bool EmitLTOSummary =
           (CodeGenOpts.PrepareForLTO &&
+           !CodeGenOpts.DisableLLVMPasses &&
            llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
                llvm::Triple::Apple);
       if (EmitLTOSummary && !TheModule->getModuleFlag("ThinLTO"))
@@ -1014,7 +1015,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
     break;
 
   case Backend_EmitBC:
-    if (CodeGenOpts.PrepareForThinLTO) {
+    if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
       if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
         ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
         if (!ThinLinkOS)
@@ -1027,6 +1028,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
       // targets
       bool EmitLTOSummary =
           (CodeGenOpts.PrepareForLTO &&
+           !CodeGenOpts.DisableLLVMPasses &&
            llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
                llvm::Triple::Apple);
       if (EmitLTOSummary && !TheModule->getModuleFlag("ThinLTO"))
diff --git a/test/CodeGen/summary-index-unnamed-global.ll b/test/CodeGen/summary-index-unnamed-global.ll
new file mode 100644 (file)
index 0000000..056c386
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc -disable-llvm-passes -x ir < %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+; RUN: %clang_cc1 -flto=thin -triple x86_64-pc-linux-gnu -emit-llvm-bc -disable-llvm-passes -x ir < %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+; RUN: %clang_cc1 -fexperimental-new-pass-manager -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc -disable-llvm-passes -x ir < %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+; RUN: %clang_cc1 -fexperimental-new-pass-manager -flto=thin -triple x86_64-pc-linux-gnu -emit-llvm-bc -disable-llvm-passes -x ir < %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+
+; CHECK-NOT:GLOBALVAL_SUMMARY_BLOCK
+
+; Make sure this doesn't crash, and we don't try to emit a module summary.
+; (The command is roughly emulating what -save-temps would do.)
+@0 = global i32 0