Index: clang/lib/Driver/ToolChains/Cuda.cpp =================================================================== --- clang/lib/Driver/ToolChains/Cuda.cpp +++ clang/lib/Driver/ToolChains/Cuda.cpp @@ -80,9 +80,19 @@ // In decreasing order so we prefer newer versions to older versions. std::initializer_list Versions = {"8.0", "7.5", "7.0"}; + // Special case for Debian to have nvidia-cuda-toolkit work + // out of the box. More info on http://bugs.debian.org/882505 + const char *NvidiaCudaToolkit = + (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu()) + ? "/usr/lib/cuda" + : nullptr; + if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) { - Candidates.emplace_back( - Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str()); + std::string CudaPath = + Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str(); + Candidates.emplace_back(CudaPath); + if (NvidiaCudaToolkit && CudaPath == "/usr") + Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit); } else if (HostTriple.isOSWindows()) { for (const char *Ver : Versions) Candidates.emplace_back( @@ -114,10 +124,8 @@ for (const char *Ver : Versions) Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver); - if (Distro(D.getVFS()).IsDebian()) - // Special case for Debian to have nvidia-cuda-toolkit work - // out of the box. More info on http://bugs.debian.org/882505 - Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda"); + if (NvidiaCudaToolkit) + Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit); } bool NoCudaLib = Args.hasArg(options::OPT_nocudalib);