@@ -1759,6 +1759,19 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
17591759 AnnotateDiagnostics (diagnostic_manager);
17601760 };
17611761
1762+ auto verify = [&](llvm::Module &module ) {
1763+ std::string Error;
1764+ llvm::raw_string_ostream MsgsOS (Error);
1765+ if (llvm::verifyModule (module , &MsgsOS)) {
1766+ LLDB_LOG (log, " IRGeneration failed with error: {0}" , Error);
1767+ diagnostic_manager.AddDiagnostic (
1768+ " The expression could not be compiled" ,
1769+ eSeverityError, eDiagnosticOriginLLDB);
1770+ return parse_result_failure;
1771+ }
1772+ return ParseResult::success;
1773+ };
1774+
17621775 // In the case of playgrounds, we turn all rewriting functionality off.
17631776 const bool repl = m_options.GetREPLEnabled ();
17641777 const bool playground = m_options.GetPlaygroundTransformEnabled ();
@@ -2088,11 +2101,16 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
20882101 std::move (sil_module), " lldb_module" ,
20892102 swift::PrimarySpecificPaths (" " , parsed_expr->main_filename ),
20902103 llvm::ArrayRef<std::string>(), llvm::ArrayRef<std::string>());
2091-
20922104 if (GenModule) {
2105+ auto parse_result = verify (*GenModule.getModule ());
2106+ if (parse_result != ParseResult::success)
2107+ return parse_result;
20932108 swift::performLLVMOptimizations (
20942109 IRGenOpts, m_swift_ast_ctx.GetDiagnosticEngine (), nullptr ,
20952110 GenModule.getModule (), GenModule.getTargetMachine (), nullptr );
2111+ parse_result = verify (*GenModule.getModule ());
2112+ if (parse_result != ParseResult::success)
2113+ return parse_result;
20962114 }
20972115 auto ContextAndModule = std::move (GenModule).release ();
20982116 m_llvm_context.reset (ContextAndModule.first );
@@ -2177,12 +2195,9 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
21772195 std::lock_guard<std::recursive_mutex> global_context_locker (
21782196 IRExecutionUnit::GetLLVMGlobalContextMutex ());
21792197
2180- bool has_errors = LLVMVerifyModule ((LLVMOpaqueModule *)m_module.get (),
2181- LLVMReturnStatusAction, nullptr );
2182- if (has_errors) {
2183- diagnostic_manager.PutString (eSeverityInfo, " LLVM verification error" );
2184- return parse_result_failure;
2185- }
2198+ ParseResult parse_result = verify (*m_module.get ());
2199+ if (parse_result != ParseResult::success)
2200+ return parse_result;
21862201 }
21872202
21882203 if (expr_diagnostics->HasErrors ()) {
0 commit comments