Author: Alexey Bataev Date: 2022-02-21T12:28:47-08:00 New Revision: f9c3310d32c62b28c10084a0104563aeeecc06ec
URL: https://github.com/llvm/llvm-project/commit/f9c3310d32c62b28c10084a0104563aeeecc06ec DIFF: https://github.com/llvm/llvm-project/commit/f9c3310d32c62b28c10084a0104563aeeecc06ec.diff LOG: [OPENMP]Fix PR49366: crash on VLAs in task untied regions. We need to capture the local variables into a record in task untied regions but clang does not support record with VLA data members. Differential Revision: https://reviews.llvm.org/D99436 Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/SemaType.cpp clang/test/OpenMP/task_messages.cpp clang/test/OpenMP/taskloop_loop_messages.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1854c8e522b82..11fcd5ff5a323 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10893,6 +10893,8 @@ def err_omp_clause_requires_dispatch_construct : Error< "'%0' clause requires 'dispatch' context selector">; def err_omp_append_args_with_varargs : Error< "'append_args' is not allowed with varargs functions">; +def err_openmp_vla_in_task_untied : Error< + "variable length arrays are not supported in OpenMP tasking regions with 'untied' clause">; } // end of OpenMP category let CategoryName = "Related Result Type Issue" in { diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index dfa12ad40b72a..2d47a20711817 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -10688,6 +10688,10 @@ class Sema final { void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, const FunctionDecl *Callee, SourceLocation Loc); + + /// Return true if currently in OpenMP task with untied clause context. + bool isInOpenMPTaskUntiedContext() const; + /// Return true inside OpenMP declare target region. bool isInOpenMPDeclareTargetContext() const { return !DeclareTargetNesting.empty(); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 43386c1ef8edb..ad8d304ef43c3 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -176,6 +176,7 @@ class DSAStackTy { bool HasMutipleLoops = false; const Decl *PossiblyLoopCounter = nullptr; bool NowaitRegion = false; + bool UntiedRegion = false; bool CancelRegion = false; bool LoopStart = false; bool BodyComplete = false; @@ -851,6 +852,15 @@ class DSAStackTy { return Parent->NowaitRegion; return false; } + /// Marks current region as untied (it has a 'untied' clause). + void setUntiedRegion(bool IsUntied = true) { + getTopOfStack().UntiedRegion = IsUntied; + } + /// Return true if current region is untied. + bool isUntiedRegion() const { + const SharingMapTy *Top = getTopOfStackOrNull(); + return Top ? Top->UntiedRegion : false; + } /// Marks parent region as cancel region. void setParentCancelRegion(bool Cancel = true) { if (SharingMapTy *Parent = getSecondOnStackOrNull()) @@ -2158,6 +2168,11 @@ unsigned Sema::getOpenMPNestingLevel() const { return DSAStack->getNestingLevel(); } +bool Sema::isInOpenMPTaskUntiedContext() const { + return isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) && + DSAStack->isUntiedRegion(); +} + bool Sema::isInOpenMPTargetExecutionDirective() const { return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) && !DSAStack->isClauseParsingMode()) || @@ -16232,6 +16247,7 @@ OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc) { + DSAStack->setUntiedRegion(); return new (Context) OMPUntiedClause(StartLoc, EndLoc); } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 74969749e54ae..35d4c386211e5 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2458,6 +2458,9 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, } else if (isSFINAEContext()) { VLADiag = diag::err_vla_in_sfinae; VLAIsError = true; + } else if (getLangOpts().OpenMP && isInOpenMPTaskUntiedContext()) { + VLADiag = diag::err_openmp_vla_in_task_untied; + VLAIsError = true; } else { VLADiag = diag::ext_vla; VLAIsError = false; diff --git a/clang/test/OpenMP/task_messages.cpp b/clang/test/OpenMP/task_messages.cpp index 13cbfb6c45693..86a3f0d481316 100644 --- a/clang/test/OpenMP/task_messages.cpp +++ b/clang/test/OpenMP/task_messages.cpp @@ -173,7 +173,7 @@ int main(int argc, char **argv) { int &b = a; S sa; S &sb = sa; - int r; + int r; // expected-note {{declared here}} #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} foo(); #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}} @@ -330,6 +330,12 @@ int main(int argc, char **argv) { // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}} #pragma omp task mergeable mergeable ++r; +// expected-error@+4 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}} +// expected-note@+3 {{read of non-const variable 'r' is not allowed in a constant expression}} +#pragma omp task untied + { + int array[r]; + } volatile omp_event_handle_t evt; omp_event_handle_t sevt; const omp_event_handle_t cevt = evt; diff --git a/clang/test/OpenMP/taskloop_loop_messages.cpp b/clang/test/OpenMP/taskloop_loop_messages.cpp index b3b24e96abc9d..677bb3c012fae 100644 --- a/clang/test/OpenMP/taskloop_loop_messages.cpp +++ b/clang/test/OpenMP/taskloop_loop_messages.cpp @@ -691,7 +691,7 @@ void test_loop_break() { void test_loop_eh() { const int N = 100; - float a[N], b[N], c[N]; + float a[N], b[N], c[N]; // expected-note {{declared here}} #pragma omp parallel #pragma omp taskloop for (int i = 0; i < 10; i++) { @@ -729,6 +729,13 @@ void test_loop_eh() { void g() { throw 0; } }; } +// expected-error@+5 {{variable length arrays are not supported in OpenMP tasking regions with 'untied' clause}} +// expected-note@+4 {{read of non-constexpr variable 'c' is not allowed in a constant expression}} +#pragma omp taskloop untied + { + for (int i = 0; i < 10; ++i) + int array[(int)c[0]]; + } } void test_loop_firstprivate_lastprivate() { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits