@@ -862,6 +862,23 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
862
862
}
863
863
}
864
864
865
+ Expected<BitcodeModule> clang::FindThinLTOModule (MemoryBufferRef MBRef) {
866
+ Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList (MBRef);
867
+ if (!BMsOrErr)
868
+ return BMsOrErr.takeError ();
869
+
870
+ // The bitcode file may contain multiple modules, we want the one with a
871
+ // summary.
872
+ for (BitcodeModule &BM : *BMsOrErr) {
873
+ Expected<bool > HasSummary = BM.hasSummary ();
874
+ if (HasSummary && *HasSummary)
875
+ return BM;
876
+ }
877
+
878
+ return make_error<StringError>(" Could not find module summary" ,
879
+ inconvertibleErrorCode ());
880
+ }
881
+
865
882
static void runThinLTOBackend (ModuleSummaryIndex *CombinedIndex, Module *M,
866
883
std::unique_ptr<raw_pwrite_stream> OS,
867
884
std::string SampleProfile) {
@@ -899,32 +916,15 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
899
916
return ;
900
917
}
901
918
902
- Expected<std::vector<BitcodeModule>> BMsOrErr =
903
- getBitcodeModuleList (**MBOrErr);
904
- if (!BMsOrErr) {
905
- handleAllErrors (BMsOrErr.takeError (), [&](ErrorInfoBase &EIB) {
919
+ Expected<BitcodeModule> BMOrErr = FindThinLTOModule (**MBOrErr);
920
+ if (!BMOrErr) {
921
+ handleAllErrors (BMOrErr.takeError (), [&](ErrorInfoBase &EIB) {
906
922
errs () << " Error loading imported file '" << I.first ()
907
923
<< " ': " << EIB.message () << ' \n ' ;
908
924
});
909
925
return ;
910
926
}
911
-
912
- // The bitcode file may contain multiple modules, we want the one with a
913
- // summary.
914
- bool FoundModule = false ;
915
- for (BitcodeModule &BM : *BMsOrErr) {
916
- Expected<bool > HasSummary = BM.hasSummary ();
917
- if (HasSummary && *HasSummary) {
918
- ModuleMap.insert ({I.first (), BM});
919
- FoundModule = true ;
920
- break ;
921
- }
922
- }
923
- if (!FoundModule) {
924
- errs () << " Error loading imported file '" << I.first ()
925
- << " ': Could not find module summary\n " ;
926
- return ;
927
- }
927
+ ModuleMap.insert ({I.first (), *BMOrErr});
928
928
929
929
OwnedImports.push_back (std::move (*MBOrErr));
930
930
}
0 commit comments