[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 02:12:49 PST 2018


vitalybuka created this revision.
vitalybuka added reviewers: pcc, tejohnson.
Herald added subscribers: eraman, inglorion, mehdi_amini.

Sometimes -flto=thin can produce regular LTO object files. Then backend may
receive them with -fthinlto-index= flag. Previous behavior was to report
error in this case. To avoid error build system needs to detect that
-flto=thin produced non-ThinLTO output. This can be quite complicated
and inefficient assuming that usually build system does not need to parse
object files.

As workaround we can just ignore -fthinlto-index= and fall-back to
non-ThinLTO version.


https://reviews.llvm.org/D42680

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


Index: clang/test/CodeGen/thinlto_backend.ll
===================================================================
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and run non-ThinLTO compilation which
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -946,16 +946,17 @@
       });
       return {};
     };
-
     Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef);
-    if (!BMOrErr)
-      return DiagErrors(BMOrErr.takeError());
-
-    Expected<std::unique_ptr<llvm::Module>> MOrErr =
-        BMOrErr->parseModule(*VMContext);
-    if (!MOrErr)
-      return DiagErrors(MOrErr.takeError());
-    return std::move(*MOrErr);
+    if (BMOrErr) {
+      Expected<std::unique_ptr<llvm::Module>> MOrErr =
+          BMOrErr->parseModule(*VMContext);
+      if (!MOrErr)
+        return DiagErrors(MOrErr.takeError());
+      return std::move(*MOrErr);
+    } else {
+      // Suppress error and fall-back to regular parsing.
+      handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {});
+    }
   }
 
   llvm::SMDiagnostic Err;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42680.131936.patch
Type: text/x-patch
Size: 1704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180130/62da00fe/attachment.bin>


More information about the cfe-commits mailing list