@@ -394,36 +394,48 @@ Interpreter::outOfProcessJITBuilder(JITConfig Config) {
394394
395395llvm::Expected<std::string>
396396Interpreter::getOrcRuntimePath (const driver::ToolChain &TC) {
397- std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath ();
398- std::optional<std::string> ResourceDir = TC.getRuntimePath ();
397+ const std::array<const char *, 3 > OrcRTLibNames = {
398+ " liborc_rt.a" , " liborc_rt_osx.a" , " liborc_rt-x86_64.a" };
399+
400+ auto findInDir = [&](llvm::StringRef Base) -> std::optional<std::string> {
401+ for (const char *LibName : OrcRTLibNames) {
402+ llvm::SmallString<256 > CandidatePath (Base);
403+ llvm::sys::path::append (CandidatePath, LibName);
404+ if (llvm::sys::fs::exists (CandidatePath))
405+ return std::string (CandidatePath.str ());
406+ }
407+ return std::nullopt ;
408+ };
409+
410+ std::string SearchedPaths;
399411
400- if (!CompilerRTPath) {
412+ if (std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath ()) {
413+ if (auto Found = findInDir (*CompilerRTPath))
414+ return *Found;
415+ SearchedPaths += *CompilerRTPath;
416+ } else {
401417 return llvm::make_error<llvm::StringError>(" CompilerRT path not found" ,
402418 std::error_code ());
403419 }
404420
405- const std::array<const char *, 3 > OrcRTLibNames = {
406- " liborc_rt.a" , " liborc_rt_osx.a" , " liborc_rt-x86_64.a" };
407-
408- for (const char *LibName : OrcRTLibNames) {
409- llvm::SmallString<256 > CandidatePath ((*CompilerRTPath).c_str ());
410- llvm::sys::path::append (CandidatePath, LibName);
411-
412- if (llvm::sys::fs::exists (CandidatePath)) {
413- return CandidatePath.str ().str ();
414- }
421+ if (std::optional<std::string> ResourceDir = TC.getRuntimePath ()) {
422+ if (auto Found = findInDir (*ResourceDir))
423+ return *Found;
424+ if (!SearchedPaths.empty ())
425+ SearchedPaths += " ; " ;
426+ SearchedPaths += *ResourceDir;
427+ } else {
428+ return llvm::make_error<llvm::StringError>(" ResourceDir path not found" ,
429+ std::error_code ());
415430 }
416431
417432 return llvm::make_error<llvm::StringError>(
418- llvm::Twine (" OrcRuntime library not found in: " ) + (*CompilerRTPath) ,
433+ llvm::Twine (" OrcRuntime library not found in: " ) + SearchedPaths ,
419434 std::error_code ());
420435}
421436
422437llvm::Expected<std::unique_ptr<Interpreter>>
423438Interpreter::create (std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
424- llvm::Error Err = llvm::Error::success ();
425-
426- std::unique_ptr<llvm::orc::LLJITBuilder> JB;
427439
428440 if (Config.IsOutOfProcess ) {
429441 const TargetInfo &TI = CI->getTarget ();
@@ -453,6 +465,9 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
453465 }
454466 }
455467
468+ llvm::Error Err = llvm::Error::success ();
469+ std::unique_ptr<llvm::orc::LLJITBuilder> JB;
470+
456471 auto Interp = std::unique_ptr<Interpreter>(new Interpreter (
457472 std::move (CI), Err, std::move (JB), /* Consumer=*/ nullptr , Config));
458473 if (auto E = std::move (Err))
0 commit comments