From: Artem Belevich Date: Tue, 28 Nov 2017 18:51:42 +0000 (+0000) Subject: [CUDA] Report "unsupported VLA" errors only on device side. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e9489a2da9a6008eb205dfdbb481f36c12a9c023;p=clang [CUDA] Report "unsupported VLA" errors only on device side. 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 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b00cf7311b..4d411446bd 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -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. diff --git a/test/SemaCUDA/call-stack-for-deferred-err.cu b/test/SemaCUDA/call-stack-for-deferred-err.cu index ddcaabf4ef..35f71dd0f1 100644 --- a/test/SemaCUDA/call-stack-for-deferred-err.cu +++ b/test/SemaCUDA/call-stack-for-deferred-err.cu @@ -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" diff --git a/test/SemaCUDA/no-call-stack-for-immediate-errs.cu b/test/SemaCUDA/no-call-stack-for-immediate-errs.cu index 6dc98695c1..f7e9eb7e92 100644 --- a/test/SemaCUDA/no-call-stack-for-immediate-errs.cu +++ b/test/SemaCUDA/no-call-stack-for-immediate-errs.cu @@ -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" diff --git a/test/SemaCUDA/vla.cu b/test/SemaCUDA/vla.cu index f0d1ba595d..b65ae5e5fe 100644 --- a/test/SemaCUDA/vla.cu +++ b/test/SemaCUDA/vla.cu @@ -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"