Skip to content

Commit b7e415f

Browse files
committed
[HIP] Fix environment variable HIP_DEVICE_LIB_PATH
Currently device lib path set by environment variable HIP_DEVICE_LIB_PATH does not work due to extra "-L" added to each entry. This patch fixes that by allowing argument name to be empty in addDirectoryList. Differential Revision: https://reviews.llvm.org/D73299
1 parent c4267b7 commit b7e415f

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void tools::addDirectoryList(const ArgList &Args, ArgStringList &CmdArgs,
9191
return; // Nothing to do.
9292

9393
StringRef Name(ArgName);
94-
if (Name.equals("-I") || Name.equals("-L"))
94+
if (Name.equals("-I") || Name.equals("-L") || Name.empty())
9595
CombinedArg = true;
9696

9797
StringRef Dirs(DirList);

clang/lib/Driver/ToolChains/CommonArgs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
9494

9595
bool isUseSeparateSections(const llvm::Triple &Triple);
9696

97+
/// \p EnvVar is split by system delimiter for environment variables.
98+
/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
99+
/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
100+
/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
101+
/// itself is added.
97102
void addDirectoryList(const llvm::opt::ArgList &Args,
98103
llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
99104
const char *EnvVar);

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void HIPToolChain::addClangTargetOptions(
327327
DriverArgs.getAllArgValues(options::OPT_hip_device_lib_path_EQ))
328328
LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
329329

330-
addDirectoryList(DriverArgs, LibraryPaths, "-L", "HIP_DEVICE_LIB_PATH");
330+
addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
331331

332332
llvm::SmallVector<std::string, 10> BCLibs;
333333

clang/test/Driver/hip-device-libs.hip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
2020
// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD
2121

22+
// Test environment variable HIP_DEVICE_LIB_PATH
23+
24+
// RUN: HIP_DEVICE_LIB_PATH=%S/Inputs/hip_dev_lib \
25+
// RUN: %clang -### -target x86_64-linux-gnu \
26+
// RUN: -x hip --cuda-gpu-arch=gfx900 \
27+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
28+
// RUN: 2>&1 | FileCheck %s --check-prefixes=COM
2229

2330
// COM: {{"[^"]*clang[^"]*"}}
2431
// COM-SAME: "-mlink-builtin-bitcode" "{{.*}}hip.amdgcn.bc"

0 commit comments

Comments
 (0)