-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Flang] Add semantics checks for cray pointer usage in DSA list #123171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flang] Add semantics checks for cray pointer usage in DSA list #123171
Conversation
Problems: - Cray pointee cannot be used in the DSA list - Cray pointer has to be in DSA list when cray pointee is used in the default (none) region Fix: Added required semantic checks along the tests
@llvm/pr-subscribers-flang-openmp Author: Thirumalai Shaktivel (Thirumalai-Shaktivel) ChangesFix failure caused by this PR: #121028 Failure: Full diff: https://github.com/llvm/llvm-project/pull/123171.diff 1 Files Affected:
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9cbc61391ba1fb..85159cb5ce0685 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2115,12 +2115,10 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
static bool IsPrivatizable(const Symbol *sym) {
auto *misc{sym->detailsIf<MiscDetails>()};
return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
- (!semantics::IsAssumedSizeArray(
- *sym) || /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
- (sym->test(Symbol::Flag::CrayPointee) &&
- // If CrayPointer is among the DSA list then the
- // CrayPointee is Privatizable
- &semantics::GetCrayPointer(*sym))) &&
+ (!semantics::IsAssumedSizeArray(*sym) /* OpenMP 5.2, 5.1.1: Assumed-size
+ arrays are shared */ ||
+ sym->test(Symbol::Flag::CrayPointee) /* If CrayPointer is among the
+ DSA list then the CrayPointee is Privatizable */) &&
!sym->owner().IsDerivedType() &&
sym->owner().kind() != Scope::Kind::ImpliedDos &&
!sym->detailsIf<semantics::AssocEntityDetails>() &&
|
@llvm/pr-subscribers-flang-semantics Author: Thirumalai Shaktivel (Thirumalai-Shaktivel) ChangesFix failure caused by this PR: #121028 Failure: Full diff: https://github.com/llvm/llvm-project/pull/123171.diff 1 Files Affected:
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9cbc61391ba1fb..85159cb5ce0685 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2115,12 +2115,10 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
static bool IsPrivatizable(const Symbol *sym) {
auto *misc{sym->detailsIf<MiscDetails>()};
return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
- (!semantics::IsAssumedSizeArray(
- *sym) || /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
- (sym->test(Symbol::Flag::CrayPointee) &&
- // If CrayPointer is among the DSA list then the
- // CrayPointee is Privatizable
- &semantics::GetCrayPointer(*sym))) &&
+ (!semantics::IsAssumedSizeArray(*sym) /* OpenMP 5.2, 5.1.1: Assumed-size
+ arrays are shared */ ||
+ sym->test(Symbol::Flag::CrayPointee) /* If CrayPointer is among the
+ DSA list then the CrayPointee is Privatizable */) &&
!sym->owner().IsDerivedType() &&
sym->owner().kind() != Scope::Kind::ImpliedDos &&
!sym->detailsIf<semantics::AssocEntityDetails>() &&
|
I have a doubt, Consider an example program test
real :: pte(*)
! pointer(pte, ptr)
end program For which, |
c705905
to
134129c
Compare
!semantics::IsAssumedSizeArray(*sym) || | ||
// If CrayPointer is among the DSA list then the | ||
// CrayPointee is Privatizable | ||
sym->test(Symbol::Flag::CrayPointee)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, would checking only for CrayPointee be right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the compilation failure due to the use of &
in &semantics::GetCrayPointer(*sym))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It fails in flang-aarch64-libcxx
and It says the following:
[...]
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/../clang/include -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o -MF tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o.d -o tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/resolve-directives.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/flang/lib/Semantics/resolve-directives.cpp
../llvm-project/flang/lib/Semantics/resolve-directives.cpp:2123:16: error: reference cannot be bound to dereferenced null pointer in well-defined C++ code; pointer may be assumed to always convert to true [-Werror,-Wundefined-bool-conversion]
2120 | (sym->test(Symbol::Flag::CrayPointee) &&
| ~~
2121 | // If CrayPointer is among the DSA list then the
2122 | // CrayPointee is Privatizable
2123 | &semantics::GetCrayPointer(*sym))) &&
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../llvm-project/flang/include/flang/Semantics/tools.h:315:15: note: 'GetCrayPointer' returns a reference
315 | const Symbol &GetCrayPointer(const Symbol &crayPointee);
| ^
1 error generated.
Can you revert the patch so that the bots pass? |
I am not very familiar with Cray pointers. Would @DanielCChen or @kkwli know? |
I have reverted the original patch (#123220) since we have not concluded. Hope it is OK. |
The example code is not standard conforming. I modified the code to make it executable and hopefully it will illustrate how CrayPointer works.
|
Here is another example, that I was trying to compile and make it work subroutine test_cray_pointer_usage
implicit none
real(8) :: var(*), pointee(2)
pointer(ivar, var)
pointee = 42.0
ivar = loc(pointee)
!$omp parallel num_threads(2) default(none)
! ERROR: The DEFAULT(NONE) clause requires that the Cray Pointer 'ivar' must be listed in a data-sharing attribute clause
print *, var(1)
!$omp end parallel
! ERROR: Cray Pointee 'var' may not appear in PRIVATE clause, use Cray Pointer 'ivar' instead
!$omp parallel num_threads(2) default(none) private(var)
print *, var(1)
!$omp end parallel
!$omp parallel num_threads(2) default(none) firstprivate(ivar)
print *, var(1)
!$omp end parallel
!$omp parallel num_threads(2) default(private) shared(ivar)
print *, var(1)
!$omp end parallel
end subroutine test_cray_pointer_usage |
Thank you, I will push changes here. |
134129c
to
538a41c
Compare
Ready for review. |
Do we need to have the same check for other DSA clauses (e.g. linear)? |
Yes. I missed them, thanks for noticing. Apart from Linear and LastPrivate, do you see anything else missing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM but I don't know enough about cray pointers to approve
I think linear and lastprivate are the ones missing for 5.0 support. The list of data-sharing attribute clause is extended to other clauses in 6.0 that we can leave it to another PR. |
@kkwli This PR is ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks.
Thanks for the reviews! |
Fix failure caused by this PR: #121028
Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474