@@ -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 ();
@@ -2091,9 +2104,15 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
20912104 llvm::ArrayRef<std::string>());
20922105
20932106 if (GenModule) {
2107+ auto parse_result = verify (*GenModule.getModule ());
2108+ if (parse_result != ParseResult::success)
2109+ return parse_result;
20942110 swift::performLLVMOptimizations (
20952111 IRGenOpts, m_swift_ast_ctx.GetDiagnosticEngine (), nullptr ,
20962112 GenModule.getModule (), GenModule.getTargetMachine (), nullptr );
2113+ parse_result = verify (*GenModule.getModule ());
2114+ if (parse_result != ParseResult::success)
2115+ return parse_result;
20972116 }
20982117 auto ContextAndModule = std::move (GenModule).release ();
20992118 m_llvm_context.reset (ContextAndModule.first );
@@ -2178,12 +2197,9 @@ SwiftExpressionParser::Parse(DiagnosticManager &diagnostic_manager,
21782197 std::lock_guard<std::recursive_mutex> global_context_locker (
21792198 IRExecutionUnit::GetLLVMGlobalContextMutex ());
21802199
2181- bool has_errors = LLVMVerifyModule ((LLVMOpaqueModule *)m_module.get (),
2182- LLVMReturnStatusAction, nullptr );
2183- if (has_errors) {
2184- diagnostic_manager.PutString (eSeverityInfo, " LLVM verification error" );
2185- return parse_result_failure;
2186- }
2200+ ParseResult parse_result = verify (*m_module.get ());
2201+ if (parse_result != ParseResult::success)
2202+ return parse_result;
21872203 }
21882204
21892205 if (expr_diagnostics->HasErrors ()) {
0 commit comments