From: Samuel Antao Date: Thu, 28 Jul 2016 14:29:18 +0000 (+0000) Subject: [OpenMP][CUDA] Do not forward OpenMP flags for CUDA device actions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15f36df4275ac914ffb3af8078b13ed035090453;p=clang [OpenMP][CUDA] Do not forward OpenMP flags for CUDA device actions. Summary: This patch prevents OpenMP flags from being forwarded to CUDA device commands. That was causing the CUDA frontend to attempt to emit OpenMP code which is not supported. This fixes the bug reported in https://llvm.org/bugs/show_bug.cgi?id=28723. Reviewers: hfinkel, carlo.bertolli, arpith-jacob, kkwli0, tra, ABataev Subscribers: caomhin, cfe-commits Differential Revision: https://reviews.llvm.org/D22895 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276979 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4bf0e718fa..7a76405629 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -5008,9 +5008,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree); Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); - // Forward flags for OpenMP + // Forward flags for OpenMP. We don't do this if the current action is an + // device offloading action. + // + // TODO: Allow OpenMP offload actions when they become available. if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, - options::OPT_fno_openmp, false)) { + options::OPT_fno_openmp, false) && + JA.isDeviceOffloading(Action::OFK_None)) { switch (getOpenMPRuntime(getToolChain(), Args)) { case OMPRT_OMP: case OMPRT_IOMP5: diff --git a/test/Driver/offloading-interoperability.c b/test/Driver/offloading-interoperability.c new file mode 100644 index 0000000000..f3836ee1cd --- /dev/null +++ b/test/Driver/offloading-interoperability.c @@ -0,0 +1,17 @@ +// REQUIRES: clang-driver +// REQUIRES: powerpc-registered-target +// REQUIRES: nvptx-registered-target + +// +// Verify that CUDA device commands do not get OpenMP flags. +// +// RUN: %clang -### -x cuda -target powerpc64le-linux-gnu -std=c++11 --cuda-gpu-arch=sm_35 -fopenmp %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix NO-OPENMP-FLAGS-FOR-CUDA-DEVICE +// +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE: clang{{.*}}" "-cc1" "-triple" "nvptx64-nvidia-cuda" +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NOT: -fopenmp +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: ptxas" "-m64" +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: fatbinary" "--cuda" "-64" +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: clang{{.*}}" "-cc1" "-triple" "powerpc64le--linux-gnu" +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE: -fopenmp +// NO-OPENMP-FLAGS-FOR-CUDA-DEVICE-NEXT: ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf64lppc"