From 8526031c5b984f3389089654cc410f314d533fd7 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 11 Jul 2019 20:35:31 +0000 Subject: [PATCH] [OPENMP]Improve handling of analysis of unsupported VLAs in reductions. Fixed the processing of the unsupported VLAs in the reduction clauses. Used targetDiag if the diagnostics can be delayed and emit it immediately if the target does not support VLAs and we're parsing target directive with the reduction clauses. llvm-svn: 365821 --- clang/include/clang/Sema/Sema.h | 6 ------ clang/lib/Sema/SemaOpenMP.cpp | 12 ++++++++---- clang/test/OpenMP/target_vla_messages.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 2e60ac9dfb08..8f66cda46b65 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9132,12 +9132,6 @@ public: } /// Return true inside OpenMP target region. bool isInOpenMPTargetExecutionDirective() const; - /// Return true if (un)supported features for the current target should be - /// diagnosed if OpenMP (offloading) is enabled. - bool shouldDiagnoseTargetSupportFromOpenMP() const { - return !getLangOpts().OpenMPIsDevice || isInOpenMPDeclareTargetContext() || - isInOpenMPTargetExecutionDirective(); - } /// Return the number of captured regions created for an OpenMP directive. static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 3a02b6ae02f5..b669929e655f 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -12140,10 +12140,14 @@ static bool actOnOMPReductionKindClause( if ((OASE && !ConstantLengthOASE) || (!OASE && !ASE && D->getType().getNonReferenceType()->isVariablyModifiedType())) { - if (!Context.getTargetInfo().isVLASupported() && - S.shouldDiagnoseTargetSupportFromOpenMP()) { - S.Diag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; - S.Diag(ELoc, diag::note_vla_unsupported); + if (!Context.getTargetInfo().isVLASupported()) { + if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective())) { + S.Diag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; + S.Diag(ELoc, diag::note_vla_unsupported); + } else { + S.targetDiag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; + S.targetDiag(ELoc, diag::note_vla_unsupported); + } continue; } // For arrays/array sections only: diff --git a/clang/test/OpenMP/target_vla_messages.cpp b/clang/test/OpenMP/target_vla_messages.cpp index 30a275172426..cf6a024c6ba5 100644 --- a/clang/test/OpenMP/target_vla_messages.cpp +++ b/clang/test/OpenMP/target_vla_messages.cpp @@ -206,4 +206,10 @@ void for_reduction(int arg) { #pragma omp parallel #pragma omp for reduction(+: vla[0:arg]) for (int i = 0; i < arg; i++) ; +#ifdef NO_VLA + // expected-error@+3 {{cannot generate code for reduction on array section, which requires a variable length array}} + // expected-note@+2 {{variable length arrays are not supported for the current target}} +#endif +#pragma omp target reduction(+ : vla[0:arg]) + for (int i = 0; i < arg; i++) ; }