diff options
| author | Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de> | 2017-02-22 06:49:10 +0000 |
|---|---|---|
| committer | Jonas Hahnfeld <Hahnfeld@itc.rwth-aachen.de> | 2017-02-22 06:49:10 +0000 |
| commit | 64a9e3c530b0b034ff7de1277dd648ba5b95c6f6 (patch) | |
| tree | cf4a41a36f6e7790a24777fde8063f131c412a87 /clang/lib | |
| parent | 9011aca5f4e8b3761626fd99cfb04dd260a40df8 (diff) | |
| download | bcm5719-llvm-64a9e3c530b0b034ff7de1277dd648ba5b95c6f6.tar.gz bcm5719-llvm-64a9e3c530b0b034ff7de1277dd648ba5b95c6f6.zip | |
[OpenMP] Generate better diagnostics for cancel and cancellation point
checkNestingOfRegions uses CancelRegion to determine whether cancel and
cancellation point are valid in the given nesting. This leads to unuseful
diagnostics if CancelRegion is invalid. The given test case has produced:
region cannot be closely nested inside 'parallel' region
As a solution, introduce checkCancelRegion and call it first to get the
expected error:
one of 'for', 'parallel', 'sections' or 'taskgroup' is expected
Differential Revision: https://reviews.llvm.org/D30135
llvm-svn: 295808
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 87115054b0c..7d479974550 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1956,7 +1956,23 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, return SR; } -static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, +static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, + OpenMPDirectiveKind CancelRegion, + SourceLocation StartLoc) { + // CancelRegion is only needed for cancel and cancellation_point. + if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) + return false; + + if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || + CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) + return false; + + SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) + << getOpenMPDirectiveName(CancelRegion); + return true; +} + +static bool checkNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, OpenMPDirectiveKind CurrentRegion, const DeclarationNameInfo &CurrentName, OpenMPDirectiveKind CancelRegion, @@ -2256,7 +2272,9 @@ StmtResult Sema::ActOnOpenMPExecutableDirective( OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { StmtResult Res = StmtError(); - if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, + // First check CancelRegion which is then used in checkNestingOfRegions. + if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || + checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, StartLoc)) return StmtError(); @@ -5860,12 +5878,6 @@ StmtResult Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind CancelRegion) { - if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && - CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { - Diag(StartLoc, diag::err_omp_wrong_cancel_region) - << getOpenMPDirectiveName(CancelRegion); - return StmtError(); - } if (DSAStack->isParentNowaitRegion()) { Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; return StmtError(); @@ -5882,12 +5894,6 @@ StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind CancelRegion) { - if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && - CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { - Diag(StartLoc, diag::err_omp_wrong_cancel_region) - << getOpenMPDirectiveName(CancelRegion); - return StmtError(); - } if (DSAStack->isParentNowaitRegion()) { Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; return StmtError(); |

