From 3dfdf6a7131bde1afbbc5e4d0471bd313144700f Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Fri, 18 Oct 2024 14:58:39 -0700 Subject: [PATCH 1/2] [Driver][SYCL] Use only PATH when searching for user host compiler When using -fsycl-host-compiler, be sure that we only use the available PATH settings to find the compiler given (if given without a full PATH qualifier). This allows for only known locations to be searched for the given compiler instead of possible internal settings unknown to the user. --- clang/lib/Driver/ToolChains/Clang.cpp | 5 ++++- clang/test/Driver/sycl-host-compiler-old-model.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 5f50196e8c534..99257a914b5f1 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5194,7 +5194,10 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA, if (HostCompilerDefArg) { ExecPath = HostCompilerDefArg->getValue(); if (!ExecPath.empty() && ExecPath == llvm::sys::path::stem(ExecPath)) - ExecPath = TC.GetProgramPath(ExecPath.c_str()); + // Use PATH to find executable. + if (llvm::ErrorOr Prog = + llvm::sys::findProgramByName(ExecPath)) + ExecPath = *Prog; } // Add any user-specified arguments. diff --git a/clang/test/Driver/sycl-host-compiler-old-model.cpp b/clang/test/Driver/sycl-host-compiler-old-model.cpp index 04b75ddaa17a2..2079be7b66ffd 100644 --- a/clang/test/Driver/sycl-host-compiler-old-model.cpp +++ b/clang/test/Driver/sycl-host-compiler-old-model.cpp @@ -90,3 +90,13 @@ // CHECK_SAVE_TEMPS-NEXT: g++{{.*}} "[[APPEND_CPP]]" "-c" // CHECK_SAVE_TEMPS-SAME: "-o" "[[HOST_OBJ:.+\.o]]" // CHECK_SAVE_TEMPS-NEXT: clang-offload-bundler{{.*}} "-input=[[DEVICE_BC]]" "-input=[[HOST_OBJ]]" + +/// Test to verify binary from PATH is used +// RUN: rm -rf %t && mkdir -p %t/test_path +// RUN: touch %t/test_path/clang++ && chmod +x %t/test_path/clang++ +// RUN: env PATH=%t/test_path \ +// RUN: %clangxx -### -fsycl -fsycl-host-compiler=clang++ \ +// RUN: -fsycl-host-compiler-options=-DDUMMY_OPT --no-offload-new-driver \ +// RUN: %s 2>&1 \ +// RUN: | FileCheck -check-prefix=PATH_CHECK %s +// PATH_CHECK: {{(/|\\\\)}}test_path{{(/|\\\\)}}clang++{{.*}} "-DDUMMY_OPT" From fea636adc2d7409bb8b4e7126f43a46d2acafdc1 Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Fri, 18 Oct 2024 16:16:45 -0700 Subject: [PATCH 2/2] Improve comment and fix Windows test --- clang/lib/Driver/ToolChains/Clang.cpp | 2 +- clang/test/Driver/sycl-host-compiler-old-model.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 99257a914b5f1..34249b34015f2 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5194,7 +5194,7 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA, if (HostCompilerDefArg) { ExecPath = HostCompilerDefArg->getValue(); if (!ExecPath.empty() && ExecPath == llvm::sys::path::stem(ExecPath)) - // Use PATH to find executable. + // Use PATH to find executable passed in from -fsycl-host-compiler. if (llvm::ErrorOr Prog = llvm::sys::findProgramByName(ExecPath)) ExecPath = *Prog; diff --git a/clang/test/Driver/sycl-host-compiler-old-model.cpp b/clang/test/Driver/sycl-host-compiler-old-model.cpp index 2079be7b66ffd..1f15119cbd699 100644 --- a/clang/test/Driver/sycl-host-compiler-old-model.cpp +++ b/clang/test/Driver/sycl-host-compiler-old-model.cpp @@ -94,7 +94,7 @@ /// Test to verify binary from PATH is used // RUN: rm -rf %t && mkdir -p %t/test_path // RUN: touch %t/test_path/clang++ && chmod +x %t/test_path/clang++ -// RUN: env PATH=%t/test_path \ +// RUN: env "PATH=%t/test_path%{pathsep}%PATH%" \ // RUN: %clangxx -### -fsycl -fsycl-host-compiler=clang++ \ // RUN: -fsycl-host-compiler-options=-DDUMMY_OPT --no-offload-new-driver \ // RUN: %s 2>&1 \