This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add semantic checks for threadprivate and declare target directives
ClosedPublic

Authored by peixin on May 17 2022, 5:34 AM.

Details

Summary

This patch supports the following checks:

[5.1] 2.21.2 THREADPRIVATE Directive
The threadprivate directive must appear in the declaration section of
a scoping unit in which the common block or variable is declared.
[5.1] 2.14.7 Declare Target Directive
The directive must appear in the declaration section of a scoping unit
in which the common block or variable is declared.

Diff Detail

Event Timeline

peixin created this revision.May 17 2022, 5:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.May 17 2022, 5:34 AM
peixin added a comment.EditedMay 17 2022, 5:37 AM

@shraiysh We misunderstood this check before (https://reviews.llvm.org/D114941#inline-1099581). I confirmed this check with OpenMP committee. gfortran does not report semantic error, but it result in unspecified behaviors, and sometimes gets segmentation fault. Sent you the confirmation email.

NimishMishra accepted this revision.May 23 2022, 3:07 AM

Thank you @peixin for the patch. LGTM with one small question.

flang/test/Semantics/omp-threadprivate05.f90
39

Does it make sense to include the particular offending Name here as well? Like in case i is the offending variable, maybe we can say so explicitly in the error. Please let me know what you think about this.

This revision is now accepted and ready to land.May 23 2022, 3:07 AM
peixin added inline comments.May 23 2022, 3:55 AM
flang/test/Semantics/omp-threadprivate05.f90
39

Yes, the message should point to the "Name". The name->source in context_.Say(name->source above achieve this. The error message will be the following on terminal:

./omp-threadprivate05.f90:40:25: error: The THREADPRIVATE directive and the common block or variable in it must appear in the same declaration section of a scoping unit
      !$omp threadprivate(i, j)
                          ^

@kiranchandramohan Do you have further comments for this?

shraiysh accepted this revision.May 26 2022, 7:35 AM

@shraiysh We misunderstood this check before (https://reviews.llvm.org/D114941#inline-1099581). I confirmed this check with OpenMP committee. gfortran does not report semantic error, but it result in unspecified behaviors, and sometimes gets segmentation fault. Sent you the confirmation email.

Yes, I checked the email. Sounds good to me. Thank you for driving this discussion!

@kiranchandramohan Do you have further comments for this?

ping @kiranchandramohan

peixin added a comment.Jun 1 2022, 6:57 AM

@kiranchandramohan Is it OK to land this now?

kiranchandramohan accepted this revision.Jun 1 2022, 7:17 AM

Thanks @peixin. You do not have to wait for me if I have not requested changes and others have approved.

peixin added a comment.Jun 1 2022, 7:21 AM

Thanks @peixin. You do not have to wait for me if I have not requested changes and others have approved.

OK. Thanks.