r354690 - [OPENMP] Delayed diagnostics for VLA support.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 22 12:36:10 PST 2019


Author: abataev
Date: Fri Feb 22 12:36:10 2019
New Revision: 354690

URL: http://llvm.org/viewvc/llvm-project?rev=354690&view=rev
Log:
[OPENMP] Delayed diagnostics for VLA support.

Generalized processing of the deferred diagnostics for OpenMP/CUDA code.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/OpenMP/target_vla_messages.cpp
    cfe/trunk/test/SemaCUDA/vla.cu

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=354690&r1=354689&r2=354690&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Feb 22 12:36:10 2019
@@ -10189,6 +10189,8 @@ public:
 
     DeviceDiagBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
                       FunctionDecl *Fn, Sema &S);
+    DeviceDiagBuilder(DeviceDiagBuilder &&D);
+    DeviceDiagBuilder(const DeviceDiagBuilder &) = default;
     ~DeviceDiagBuilder();
 
     /// Convertible to bool: True if we immediately emitted an error, false if

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=354690&r1=354689&r2=354690&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Feb 22 12:36:10 2019
@@ -1409,6 +1409,16 @@ Sema::DeviceDiagBuilder::DeviceDiagBuild
   }
 }
 
+Sema::DeviceDiagBuilder::DeviceDiagBuilder(DeviceDiagBuilder &&D)
+    : S(D.S), Loc(D.Loc), DiagID(D.DiagID), Fn(D.Fn),
+      ShowCallStack(D.ShowCallStack), ImmediateDiag(D.ImmediateDiag),
+      PartialDiagId(D.PartialDiagId) {
+  // Clean the previous diagnostics.
+  D.ShowCallStack = false;
+  D.ImmediateDiag.reset();
+  D.PartialDiagId.reset();
+}
+
 Sema::DeviceDiagBuilder::~DeviceDiagBuilder() {
   if (ImmediateDiag) {
     // Emit our diagnostic and, if it was a warning or error, output a callstack

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=354690&r1=354689&r2=354690&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Feb 22 12:36:10 2019
@@ -2250,15 +2250,13 @@ QualType Sema::BuildArrayType(QualType T
   }
 
   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();
-    }
+    // CUDA device code and some other targets don't support VLAs.
+    targetDiag(Loc, (getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
+                        ? diag::err_cuda_vla
+                        : diag::err_vla_unsupported)
+        << ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice)
+                ? CurrentCUDATarget()
+                : CFT_InvalidTarget);
   }
 
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.

Modified: cfe/trunk/test/OpenMP/target_vla_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_vla_messages.cpp?rev=354690&r1=354689&r2=354690&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/target_vla_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_vla_messages.cpp Fri Feb 22 12:36:10 2019
@@ -47,7 +47,7 @@ void target_template(int arg) {
 #pragma omp target
   {
 #ifdef NO_VLA
-    // expected-error at +2 {{variable length arrays are not supported for the current target}}
+    // expected-error at +2 2 {{variable length arrays are not supported for the current target}}
 #endif
     T vla[arg];
   }
@@ -73,6 +73,9 @@ void target(int arg) {
     }
   }
 
+#ifdef NO_VLA
+    // expected-note at +2 {{in instantiation of function template specialization 'target_template<long>' requested here}}
+#endif
   target_template<long>(arg);
 }
 

Modified: cfe/trunk/test/SemaCUDA/vla.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/vla.cu?rev=354690&r1=354689&r2=354690&view=diff
==============================================================================
--- cfe/trunk/test/SemaCUDA/vla.cu (original)
+++ cfe/trunk/test/SemaCUDA/vla.cu Fri Feb 22 12:36:10 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -verify %s
-// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -verify -DHOST %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -DHOST %s
+
+#ifndef __CUDA_ARCH__
+// expected-no-diagnostics
+#endif
 
 #include "Inputs/cuda.h"
 
@@ -8,7 +12,10 @@ void host(int n) {
 }
 
 __device__ void device(int n) {
-  int x[n];  // expected-error {{cannot use variable-length arrays in __device__ functions}}
+  int x[n];
+#ifdef __CUDA_ARCH__
+  // expected-error at -2 {{cannot use variable-length arrays in __device__ functions}}
+#endif
 }
 
 __host__ __device__ void hd(int n) {




More information about the cfe-commits mailing list