]> granicus.if.org Git - clang/commitdiff
[CUDA] Report "unsupported VLA" errors only on device side.
authorArtem Belevich <tra@google.com>
Tue, 28 Nov 2017 18:51:42 +0000 (18:51 +0000)
committerArtem Belevich <tra@google.com>
Tue, 28 Nov 2017 18:51:42 +0000 (18:51 +0000)
This fixes erroneously reported CUDA compilation errors
in host-side code during device-side compilation.

I've also restricted OpenMP-specific checks to trigger only
if we're compiling with OpenMP enabled.

Differential Revision: https://reviews.llvm.org/D40275

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@319201 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
test/SemaCUDA/call-stack-for-deferred-err.cu
test/SemaCUDA/no-call-stack-for-immediate-errs.cu
test/SemaCUDA/vla.cu

index b00cf7311b977dc244645b3b9e87741f7063d8be..4d411446bd55e5469e72a51928a41fd618e389c8 100644 (file)
@@ -2180,14 +2180,17 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
     Diag(Loc, diag::err_opencl_vla);
     return QualType();
   }
-  // CUDA device code doesn't support VLAs.
-  if (getLangOpts().CUDA && T->isVariableArrayType())
-    CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
-  // Some targets don't support VLAs.
-  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported() &&
-      shouldDiagnoseTargetSupportFromOpenMP()) {
-    Diag(Loc, diag::err_vla_unsupported);
-    return QualType();
+
+  if (T->isVariableArrayType() && !Context.getTargetInfo().isVLASupported()) {
+    if (getLangOpts().CUDA) {
+      // CUDA device code doesn't support VLAs.
+      CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget();
+    } else if (!getLangOpts().OpenMP ||
+               shouldDiagnoseTargetSupportFromOpenMP()) {
+      // Some targets don't support VLAs.
+      Diag(Loc, diag::err_vla_unsupported);
+      return QualType();
+    }
   }
 
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.
index ddcaabf4ef53b781a21b9a8eba68610941985a45..35f71dd0f12463c629e00d36db5d2ea04357db6a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only -verify %s
 
 #include "Inputs/cuda.h"
 
index 6dc98695c1e3ac344c1df1d177ca0ae69040a205..f7e9eb7e9211dd191605f90197f146911dc4d861 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -fsyntax-only -verify %s
 
 #include "Inputs/cuda.h"
 
index f0d1ba595d935d38b9d516c8ae5a6a7da1da50b5..b65ae5e5fe214e9f3811d3e4c37b4092fe6388c3 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -verify -DHOST %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -verify -DHOST %s
 
 #include "Inputs/cuda.h"