Author: Joseph Huber Date: 2022-01-20T13:12:02-05:00 New Revision: af5600420b93769a5c7981d247d37ac4d61cce54
URL: https://github.com/llvm/llvm-project/commit/af5600420b93769a5c7981d247d37ac4d61cce54 DIFF: https://github.com/llvm/llvm-project/commit/af5600420b93769a5c7981d247d37ac4d61cce54.diff LOG: [OpenMP] Don't pass empty files to nvlink This patch adds and exception to the nvlink wrapper tool to not pass empty cubin files to the nvlink job. If an empty file is passed to nvlink it will cause an error indicating that the file could not be opened. This would occur if the user tried to link object files that contained offloading code with a file that didnt. This will act as a workaround until the new OpenMP offloading driver becomes the default. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D117777 Added: clang/test/Driver/Inputs/openmp_static_device_link/empty.o clang/test/Driver/Inputs/openmp_static_device_link/lib.bc Modified: clang/test/Driver/fat_archive_nvptx.cpp clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp Removed: ################################################################################ diff --git a/clang/test/Driver/Inputs/openmp_static_device_link/empty.o b/clang/test/Driver/Inputs/openmp_static_device_link/empty.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/openmp_static_device_link/lib.bc b/clang/test/Driver/Inputs/openmp_static_device_link/lib.bc new file mode 100644 index 0000000000000..1a87fd836dba2 Binary files /dev/null and b/clang/test/Driver/Inputs/openmp_static_device_link/lib.bc diff er diff --git a/clang/test/Driver/fat_archive_nvptx.cpp b/clang/test/Driver/fat_archive_nvptx.cpp index a46c44ff998cc..5413445925dd3 100644 --- a/clang/test/Driver/fat_archive_nvptx.cpp +++ b/clang/test/Driver/fat_archive_nvptx.cpp @@ -10,7 +10,8 @@ // CHECK: clang{{.*}}"-cc1"{{.*}}"-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" "[[GPU:sm_[0-9]+]]"{{.*}}"-o" "[[HOSTBC:.*.s]]" "-x" "c++"{{.*}}.cpp // CHECK: clang-offload-bundler" "-unbundle" "-type=a" "-inputs={{.*}}/Inputs/openmp_static_device_link/libFatArchive.a" "-targets=openmp-nvptx64-nvidia-cuda-[[GPU]]" "-outputs=[[DEVICESPECIFICARCHIVE:.*.a]]" "-allow-missing-bundles" // CHECK: clang-nvlink-wrapper{{.*}}"-o" "{{.*}}.out" "-arch" "[[GPU]]" "{{.*}}[[DEVICESPECIFICARCHIVE]]" -// expected-no-diagnostics +// RUN: not %clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda %s %S/Inputs/openmp_static_device_link/empty.o --libomptarget-nvptx-bc-path=%S/Inputs/openmp_static_device_link/lib.bc 2>&1 | FileCheck %s --check-prefix=EMPTY +// EMPTY-NOT: Could not open input file #ifndef HEADER #define HEADER diff --git a/clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp b/clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp index 46a4f30ba8817..7ccc284a48314 100644 --- a/clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp +++ b/clang/tools/clang-nvlink-wrapper/ClangNvlinkWrapper.cpp @@ -55,12 +55,22 @@ static cl::opt<std::string> NvlinkUserPath("nvlink-path", static cl::list<std::string> NVArgs(cl::Sink, cl::desc("<options to be passed to nvlink>...")); +static bool isEmptyFile(StringRef Filename) { + ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = + MemoryBuffer::getFileOrSTDIN(Filename, false, false); + if (std::error_code EC = BufOrErr.getError()) + return false; + return (*BufOrErr)->getBuffer().empty(); +} + static Error runNVLink(std::string NVLinkPath, SmallVectorImpl<std::string> &Args) { std::vector<StringRef> NVLArgs; NVLArgs.push_back(NVLinkPath); + StringRef Output = *(llvm::find(Args, "-o") + 1); for (auto &Arg : Args) { - NVLArgs.push_back(Arg); + if (!(sys::fs::exists(Arg) && Arg != Output && isEmptyFile(Arg))) + NVLArgs.push_back(Arg); } if (sys::ExecuteAndWait(NVLinkPath, NVLArgs)) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits