diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h --- a/clang/lib/Driver/ToolChains/CommonArgs.h +++ b/clang/lib/Driver/ToolChains/CommonArgs.h @@ -94,6 +94,11 @@ bool isUseSeparateSections(const llvm::Triple &Triple); +/// \p EnvVar is split by system delimiter for environment variables. +/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar +/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each +/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry +/// itself is added. void addDirectoryList(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *ArgName, const char *EnvVar); diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -91,7 +91,7 @@ return; // Nothing to do. StringRef Name(ArgName); - if (Name.equals("-I") || Name.equals("-L")) + if (Name.equals("-I") || Name.equals("-L") || Name.empty()) CombinedArg = true; StringRef Dirs(DirList); diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp --- a/clang/lib/Driver/ToolChains/HIP.cpp +++ b/clang/lib/Driver/ToolChains/HIP.cpp @@ -327,7 +327,7 @@ DriverArgs.getAllArgValues(options::OPT_hip_device_lib_path_EQ)) LibraryPaths.push_back(DriverArgs.MakeArgString(Path)); - addDirectoryList(DriverArgs, LibraryPaths, "-L", "HIP_DEVICE_LIB_PATH"); + addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH"); llvm::SmallVector BCLibs; diff --git a/clang/test/Driver/hip-device-libs.hip b/clang/test/Driver/hip-device-libs.hip --- a/clang/test/Driver/hip-device-libs.hip +++ b/clang/test/Driver/hip-device-libs.hip @@ -19,6 +19,13 @@ // RUN: %S/Inputs/hip_multiple_inputs/b.hip \ // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD +// Test environment variable HIP_DEVICE_LIB_PATH + +// RUN: HIP_DEVICE_LIB_PATH=%S/Inputs/hip_dev_lib \ +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: -x hip --cuda-gpu-arch=gfx900 \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM // COM: {{"[^"]*clang[^"]*"}} // COM-SAME: "-mlink-builtin-bitcode" "{{.*}}hip.amdgcn.bc"