Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,36 +394,48 @@ Interpreter::outOfProcessJITBuilder(JITConfig Config) {

llvm::Expected<std::string>
Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) {
std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath();
std::optional<std::string> ResourceDir = TC.getRuntimePath();
const std::array<const char *, 3> OrcRTLibNames = {
"liborc_rt.a", "liborc_rt_osx.a", "liborc_rt-x86_64.a"};

auto findInDir = [&](llvm::StringRef Base) -> std::optional<std::string> {
for (const char *LibName : OrcRTLibNames) {
llvm::SmallString<256> CandidatePath(Base);
llvm::sys::path::append(CandidatePath, LibName);
if (llvm::sys::fs::exists(CandidatePath))
return std::string(CandidatePath.str());
}
return std::nullopt;
};

std::string SearchedPaths;

if (!CompilerRTPath) {
if (std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath()) {
if (auto Found = findInDir(*CompilerRTPath))
return *Found;
SearchedPaths += *CompilerRTPath;
} else {
return llvm::make_error<llvm::StringError>("CompilerRT path not found",
std::error_code());
}

const std::array<const char *, 3> OrcRTLibNames = {
"liborc_rt.a", "liborc_rt_osx.a", "liborc_rt-x86_64.a"};

for (const char *LibName : OrcRTLibNames) {
llvm::SmallString<256> CandidatePath((*CompilerRTPath).c_str());
llvm::sys::path::append(CandidatePath, LibName);

if (llvm::sys::fs::exists(CandidatePath)) {
return CandidatePath.str().str();
}
if (std::optional<std::string> ResourceDir = TC.getRuntimePath()) {
if (auto Found = findInDir(*ResourceDir))
return *Found;
if (!SearchedPaths.empty())
SearchedPaths += "; ";
SearchedPaths += *ResourceDir;
} else {
return llvm::make_error<llvm::StringError>("ResourceDir path not found",
std::error_code());
}

return llvm::make_error<llvm::StringError>(
llvm::Twine("OrcRuntime library not found in: ") + (*CompilerRTPath),
llvm::Twine("OrcRuntime library not found in: ") + SearchedPaths,
std::error_code());
}

llvm::Expected<std::unique_ptr<Interpreter>>
Interpreter::create(std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
llvm::Error Err = llvm::Error::success();

std::unique_ptr<llvm::orc::LLJITBuilder> JB;

if (Config.IsOutOfProcess) {
const TargetInfo &TI = CI->getTarget();
Expand Down Expand Up @@ -453,6 +465,9 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
}
}

llvm::Error Err = llvm::Error::success();
std::unique_ptr<llvm::orc::LLJITBuilder> JB;

auto Interp = std::unique_ptr<Interpreter>(new Interpreter(
std::move(CI), Err, std::move(JB), /*Consumer=*/nullptr, Config));
if (auto E = std::move(Err))
Expand Down
1 change: 1 addition & 0 deletions clang/tools/clang-repl/ClangRepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ int main(int argc, const char **argv) {
clang::Interpreter::JITConfig Config;
Config.IsOutOfProcess = !OOPExecutor.empty() || !OOPExecutorConnect.empty();
Config.OOPExecutor = OOPExecutor;
Config.OrcRuntimePath = OrcRuntimePath;
auto SizeOrErr = getSlabAllocSize(SlabAllocateSizeString);
if (!SizeOrErr) {
llvm::logAllUnhandledErrors(SizeOrErr.takeError(), llvm::errs(), "error: ");
Expand Down
Loading