[LTO] Always mark regular LTO units with EnableSplitLTOUnit=1
authorTeresa Johnson <tejohnson@google.com>
Fri, 19 Jul 2019 23:02:58 +0000 (23:02 +0000)
committerTeresa Johnson <tejohnson@google.com>
Fri, 19 Jul 2019 23:02:58 +0000 (23:02 +0000)
Summary:
Regular LTO modules do not need LTO Unit splitting, only ThinLTO does
(they must be consistently split into regular and Thin units for
optimizations such as whole program devirtualization and lower type
tests). In order to avoid spurious errors from LTO when combining with
split ThinLTO modules, always set this flag for regular LTO modules.

Reviewers: pcc

Subscribers: mehdi_amini, Prazek, inglorion, steven_wu, dexonsmith, cfe-commits

Tags: #clang

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

llvm-svn: 366623

clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/split-lto-unit.c [new file with mode: 0644]

index 850b3db..b53d7a6 100644 (file)
@@ -852,7 +852,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
         if (!TheModule->getModuleFlag("ThinLTO"))
           TheModule->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
         TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
-                                 CodeGenOpts.EnableSplitLTOUnit);
+                                 uint32_t(1));
       }
 
       PerModulePasses.add(createBitcodeWriterPass(
diff --git a/clang/test/CodeGen/split-lto-unit.c b/clang/test/CodeGen/split-lto-unit.c
new file mode 100644 (file)
index 0000000..8e83eba
--- /dev/null
@@ -0,0 +1,12 @@
+// ; Check that -flto=thin without -fsplit-lto-unit has EnableSplitLTOUnit = 0
+// RUN: %clang_cc1 -flto=thin -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s
+// CHECK: !{i32 1, !"EnableSplitLTOUnit", i32 0}
+//
+// ; Check that -flto=thin with -fsplit-lto-unit has EnableSplitLTOUnit = 1
+// RUN: %clang_cc1 -flto=thin -fsplit-lto-unit -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --check-prefix=SPLIT
+// SPLIT: !{i32 1, !"EnableSplitLTOUnit", i32 1}
+//
+// ; Check that regular LTO has EnableSplitLTOUnit = 1
+// RUN: %clang_cc1 -flto -triple x86_64-pc-linux-gnu -emit-llvm-bc < %s | llvm-dis -o - | FileCheck %s --implicit-check-not="EnableSplitLTOUnit" --check-prefix=SPLIT
+
+int main() {}