From b7e415f37f38c65ced6d725d100790526920bc0c Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Thu, 23 Jan 2020 17:30:07 -0500 Subject: [PATCH] [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 --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +- clang/lib/Driver/ToolChains/CommonArgs.h | 5 +++++ clang/lib/Driver/ToolChains/HIP.cpp | 2 +- clang/test/Driver/hip-device-libs.hip | 7 +++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 4adccaa..bdf72a02 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -91,7 +91,7 @@ void tools::addDirectoryList(const ArgList &Args, ArgStringList &CmdArgs, 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/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h index 84b9d2c..bf1ab81 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.h +++ b/clang/lib/Driver/ToolChains/CommonArgs.h @@ -94,6 +94,11 @@ bool areOptimizationsEnabled(const llvm::opt::ArgList &Args); 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/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp index 7039dde..07af734 100644 --- a/clang/lib/Driver/ToolChains/HIP.cpp +++ b/clang/lib/Driver/ToolChains/HIP.cpp @@ -327,7 +327,7 @@ void HIPToolChain::addClangTargetOptions( 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 index 14401a94..d546645 100644 --- 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" -- 2.7.4