@@ -838,6 +838,41 @@ static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
838
838
Diags->Report (DiagID).AddString (" cannot compile inline asm" );
839
839
}
840
840
841
+ std::unique_ptr<llvm::Module> CodeGenAction::loadModule (MemoryBufferRef MBRef) {
842
+ CompilerInstance &CI = getCompilerInstance ();
843
+ SourceManager &SM = CI.getSourceManager ();
844
+
845
+ // For ThinLTO backend invocations, ensure that the context
846
+ // merges types based on ODR identifiers.
847
+ if (!CI.getCodeGenOpts ().ThinLTOIndexFile .empty ())
848
+ VMContext->enableDebugTypeODRUniquing ();
849
+
850
+ llvm::SMDiagnostic Err;
851
+ if (std::unique_ptr<llvm::Module> M = parseIR (MBRef, Err, *VMContext))
852
+ return M;
853
+
854
+ // Translate from the diagnostic info to the SourceManager location if
855
+ // available.
856
+ // TODO: Unify this with ConvertBackendLocation()
857
+ SourceLocation Loc;
858
+ if (Err.getLineNo () > 0 ) {
859
+ assert (Err.getColumnNo () >= 0 );
860
+ Loc = SM.translateFileLineCol (SM.getFileEntryForID (SM.getMainFileID ()),
861
+ Err.getLineNo (), Err.getColumnNo () + 1 );
862
+ }
863
+
864
+ // Strip off a leading diagnostic code if there is one.
865
+ StringRef Msg = Err.getMessage ();
866
+ if (Msg.startswith (" error: " ))
867
+ Msg = Msg.substr (7 );
868
+
869
+ unsigned DiagID =
870
+ CI.getDiagnostics ().getCustomDiagID (DiagnosticsEngine::Error, " %0" );
871
+
872
+ CI.getDiagnostics ().Report (Loc, DiagID) << Msg;
873
+ return {};
874
+ }
875
+
841
876
void CodeGenAction::ExecuteAction () {
842
877
// If this is an IR file, we have to treat it specially.
843
878
if (getCurrentFileKind () == IK_LLVM_IR) {
@@ -855,35 +890,10 @@ void CodeGenAction::ExecuteAction() {
855
890
if (Invalid)
856
891
return ;
857
892
858
- // For ThinLTO backend invocations, ensure that the context
859
- // merges types based on ODR identifiers.
860
- if (!CI.getCodeGenOpts ().ThinLTOIndexFile .empty ())
861
- VMContext->enableDebugTypeODRUniquing ();
862
-
863
- llvm::SMDiagnostic Err;
864
- TheModule = parseIR (MainFile->getMemBufferRef (), Err, *VMContext);
865
- if (!TheModule) {
866
- // Translate from the diagnostic info to the SourceManager location if
867
- // available.
868
- // TODO: Unify this with ConvertBackendLocation()
869
- SourceLocation Loc;
870
- if (Err.getLineNo () > 0 ) {
871
- assert (Err.getColumnNo () >= 0 );
872
- Loc = SM.translateFileLineCol (SM.getFileEntryForID (FID),
873
- Err.getLineNo (), Err.getColumnNo () + 1 );
874
- }
875
-
876
- // Strip off a leading diagnostic code if there is one.
877
- StringRef Msg = Err.getMessage ();
878
- if (Msg.startswith (" error: " ))
879
- Msg = Msg.substr (7 );
880
-
881
- unsigned DiagID =
882
- CI.getDiagnostics ().getCustomDiagID (DiagnosticsEngine::Error, " %0" );
883
-
884
- CI.getDiagnostics ().Report (Loc, DiagID) << Msg;
893
+ TheModule = loadModule (*MainFile);
894
+ if (!TheModule)
885
895
return ;
886
- }
896
+
887
897
const TargetOptions &TargetOpts = CI.getTargetOpts ();
888
898
if (TheModule->getTargetTriple () != TargetOpts.Triple ) {
889
899
CI.getDiagnostics ().Report (SourceLocation (),
0 commit comments