This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Generate better diagnostics for cancel and cancellation point
ClosedPublic

Authored by Hahnfeld on Feb 18 2017, 3:40 AM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

Hahnfeld created this revision.Feb 18 2017, 3:40 AM
ABataev edited edge metadata.Feb 20 2017, 1:24 AM

Not sure that this is better because at first, we need to be sure that this nesting is allowed. Why do we need to perform some additional analysis if nesting is not allowed at all?

Not sure that this is better because at first, we need to be sure that this nesting is allowed. Why do we need to perform some additional analysis if nesting is not allowed at all?

CheckNestingOfRegions uses CancelRegion to determine whether cancel and cancellation point may be nested inside the parent construct. However with the current code, CancelRegion would only be checked afterwards.

#pragma omp parallel
  {
#pragma omp cancellation point unknown
  }

therefore produces region cannot be closely nested inside 'parallel' region. After this change, it says one of 'for', 'parallel', 'sections' or 'taskgroup' is expected as in the test case which is better IMO.

Should I try to improve the summary to explain that?

I see. I think it is better to check the CancelRegion just before call of CheckNestingOfRegions() function. You need to extract checks for CancelRegion from ActOnOpenMPCancellationPointDirective() and ActOnOpenMPCancelDirective() functions into a standalone function and call it before CheckNestingOfRegions().

Hahnfeld updated this revision to Diff 89099.Feb 20 2017, 3:12 AM
Hahnfeld edited the summary of this revision. (Show Details)

new static function CheckCancelRegion

ABataev added inline comments.Feb 20 2017, 3:43 AM
lib/Sema/SemaOpenMP.cpp
1959 ↗(On Diff #89099)

Should be checkCancelRegion

1964–1966 ↗(On Diff #89099)

No need for braces

1968–1973 ↗(On Diff #89099)

It is better to convert this to return false and make error message and return true statement unconditional

Hahnfeld added inline comments.Feb 20 2017, 3:48 AM
lib/Sema/SemaOpenMP.cpp
1959 ↗(On Diff #89099)

It's also CheckNestingOfRegions, but can do

1968–1973 ↗(On Diff #89099)

I wanted to keep the style in CheckNestingOfRegions: That way it's easier to add more checks later on if needed like additional restrictions on CancelRegion

ABataev added inline comments.Feb 20 2017, 4:00 AM
lib/Sema/SemaOpenMP.cpp
1959 ↗(On Diff #89099)

Old formatting, this should be fixed

1968–1973 ↗(On Diff #89099)

I just meant that it's better to make it look like this:

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;
Hahnfeld added inline comments.Feb 20 2017, 4:02 AM
lib/Sema/SemaOpenMP.cpp
1968–1973 ↗(On Diff #89099)

I understood what you want it to look like. However, that style makes it impossible to add additional diagnostics to this function

ABataev added inline comments.Feb 20 2017, 4:08 AM
lib/Sema/SemaOpenMP.cpp
1968–1973 ↗(On Diff #89099)

Let's think about it later, if(!) some changes will be required

Hahnfeld updated this revision to Diff 89106.Feb 20 2017, 4:48 AM
Hahnfeld marked 3 inline comments as done.
Hahnfeld edited the summary of this revision. (Show Details)

Address review comment's and apply new naming style to checkNestingOfRegions

This revision is now accepted and ready to land.Feb 21 2017, 8:31 AM
This revision was automatically updated to reflect the committed changes.