Skip to content

Commit 3dfdf6a

Browse files
committed
[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.
1 parent d7a720c commit 3dfdf6a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5194,7 +5194,10 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
51945194
if (HostCompilerDefArg) {
51955195
ExecPath = HostCompilerDefArg->getValue();
51965196
if (!ExecPath.empty() && ExecPath == llvm::sys::path::stem(ExecPath))
5197-
ExecPath = TC.GetProgramPath(ExecPath.c_str());
5197+
// Use PATH to find executable.
5198+
if (llvm::ErrorOr<std::string> Prog =
5199+
llvm::sys::findProgramByName(ExecPath))
5200+
ExecPath = *Prog;
51985201
}
51995202

52005203
// Add any user-specified arguments.

clang/test/Driver/sycl-host-compiler-old-model.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@
9090
// CHECK_SAVE_TEMPS-NEXT: g++{{.*}} "[[APPEND_CPP]]" "-c"
9191
// CHECK_SAVE_TEMPS-SAME: "-o" "[[HOST_OBJ:.+\.o]]"
9292
// CHECK_SAVE_TEMPS-NEXT: clang-offload-bundler{{.*}} "-input=[[DEVICE_BC]]" "-input=[[HOST_OBJ]]"
93+
94+
/// Test to verify binary from PATH is used
95+
// RUN: rm -rf %t && mkdir -p %t/test_path
96+
// RUN: touch %t/test_path/clang++ && chmod +x %t/test_path/clang++
97+
// RUN: env PATH=%t/test_path \
98+
// RUN: %clangxx -### -fsycl -fsycl-host-compiler=clang++ \
99+
// RUN: -fsycl-host-compiler-options=-DDUMMY_OPT --no-offload-new-driver \
100+
// RUN: %s 2>&1 \
101+
// RUN: | FileCheck -check-prefix=PATH_CHECK %s
102+
// PATH_CHECK: {{(/|\\\\)}}test_path{{(/|\\\\)}}clang++{{.*}} "-DDUMMY_OPT"

0 commit comments

Comments
 (0)