[OpenMP][CUDA] Do not forward OpenMP flags for CUDA device actions.
authorSamuel Antao <sfantao@us.ibm.com>
Thu, 28 Jul 2016 14:29:18 +0000 (14:29 +0000)
committerSamuel Antao <sfantao@us.ibm.com>
Thu, 28 Jul 2016 14:29:18 +0000 (14:29 +0000)
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

llvm-svn: 276979

clang/lib/Driver/Tools.cpp
clang/test/Driver/offloading-interoperability.c [new file with mode: 0644]

index 4bf0e71..7a76405 100644 (file)
@@ -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/clang/test/Driver/offloading-interoperability.c b/clang/test/Driver/offloading-interoperability.c
new file mode 100644 (file)
index 0000000..f3836ee
--- /dev/null
@@ -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"