From ba1b65f4a20566405c53d4ded90b483ec9aa7d09 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 03:51:54 +0000 Subject: feat: require explicit execution mode and gate external running Require PATH or NONE at configure time. Reject -r before writing output when lli is unavailable or execution is disabled. Co-Authored-By: Claude Fable 5.1 --- tools/driver/main.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tools/driver') diff --git a/tools/driver/main.cc b/tools/driver/main.cc index a6b977a..f5373a0 100644 --- a/tools/driver/main.cc +++ b/tools/driver/main.cc @@ -48,6 +48,20 @@ int main(int argc, char **argv) { llvm::errs() << "Error: no source file specified\n"; return 1; } + std::string LliPath; + if (Run) { +#ifdef CPSC_RUN_PATH + auto Lli = llvm::sys::findProgramByName("lli"); + if (!Lli) { + llvm::errs() << "Error: -r requires lli in PATH: " << Lli.getError().message() << "\n"; + return 1; + } + LliPath = *Lli; +#else + llvm::errs() << "Error: -r is disabled in this build (CPSC_RUN_MODE=NONE)\n"; + return 1; +#endif + } if (OutputPath.empty() && !Run) { llvm::SmallString<256> DefaultPath(InputPath); llvm::sys::path::replace_extension(DefaultPath, ".ir"); @@ -108,18 +122,14 @@ int main(int argc, char **argv) { } if (!Run) return 0; - auto Lli = llvm::sys::findProgramByName("lli"); - if (!Lli) { - llvm::errs() << "Error: cannot find lli in PATH: " << Lli.getError().message() << "\n"; - return 1; - } +#ifdef CPSC_RUN_PATH llvm::SmallString<256> RunPath(OutputPath); if (auto PathError = llvm::sys::fs::make_absolute(RunPath)) { llvm::errs() << "Error: cannot resolve IR path: " << PathError.message() << "\n"; return 1; } std::string ExecutionError; - int Result = llvm::sys::ExecuteAndWait(*Lli, {*Lli, RunPath}, + int Result = llvm::sys::ExecuteAndWait(LliPath, {LliPath, RunPath}, std::nullopt, {}, 0, 0, &ExecutionError); if (Result < 0) { llvm::errs() << "Error: lli execution failed (status " << Result << "): " @@ -127,4 +137,7 @@ int main(int argc, char **argv) { return 1; } return Result; +#else + return 0; +#endif } -- cgit v1.3.1-4-g156e