Skip to content

Conversation

@kiranchandramohan
Copy link
Contributor

Fixes an issue where the compiler is trying to default privatize construct names.

Fixes #112572

Fixes an issue where the compiler is trying to default privatize
construct names.

Fixes llvm#112572
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Nov 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

Changes

Fixes an issue where the compiler is trying to default privatize construct names.

Fixes #112572


Full diff: https://github.com/llvm/llvm-project/pull/117886.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+1-1)
  • (added) flang/test/Semantics/OpenMP/critical_within_default.f90 (+17)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 80e238f3476ac8..59013619cc689d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2112,7 +2112,7 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
 
 static bool IsPrivatizable(const Symbol *sym) {
   auto *misc{sym->detailsIf<MiscDetails>()};
-  return !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
+  return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
       !semantics::IsAssumedSizeArray(
           *sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
       !sym->owner().IsDerivedType() &&
diff --git a/flang/test/Semantics/OpenMP/critical_within_default.f90 b/flang/test/Semantics/OpenMP/critical_within_default.f90
new file mode 100644
index 00000000000000..dd972e6e529492
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical_within_default.f90
@@ -0,0 +1,17 @@
+! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
+! Test that we do not make a private copy of the critical name
+
+!CHECK:  MainProgram scope: mn
+!CHECK-NEXT:    j size=4 offset=0: ObjectEntity type: INTEGER(4)
+!CHECK-NEXT:    OtherConstruct scope:
+!CHECK-NEXT:      j (OmpPrivate): HostAssoc
+!CHECK-NEXT:      k2 (OmpCriticalLock): Unknown
+program mn
+  integer :: j
+  j=2
+  !$omp parallel default(private)
+    !$omp critical(k2)
+    j=200
+    !$omp end critical(k2)
+  !$omp end parallel
+end 

@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-flang-semantics

Author: Kiran Chandramohan (kiranchandramohan)

Changes

Fixes an issue where the compiler is trying to default privatize construct names.

Fixes #112572


Full diff: https://github.com/llvm/llvm-project/pull/117886.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+1-1)
  • (added) flang/test/Semantics/OpenMP/critical_within_default.f90 (+17)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 80e238f3476ac8..59013619cc689d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2112,7 +2112,7 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
 
 static bool IsPrivatizable(const Symbol *sym) {
   auto *misc{sym->detailsIf<MiscDetails>()};
-  return !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
+  return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
       !semantics::IsAssumedSizeArray(
           *sym) && /* OpenMP 5.2, 5.1.1: Assumed-size arrays are shared*/
       !sym->owner().IsDerivedType() &&
diff --git a/flang/test/Semantics/OpenMP/critical_within_default.f90 b/flang/test/Semantics/OpenMP/critical_within_default.f90
new file mode 100644
index 00000000000000..dd972e6e529492
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/critical_within_default.f90
@@ -0,0 +1,17 @@
+! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
+! Test that we do not make a private copy of the critical name
+
+!CHECK:  MainProgram scope: mn
+!CHECK-NEXT:    j size=4 offset=0: ObjectEntity type: INTEGER(4)
+!CHECK-NEXT:    OtherConstruct scope:
+!CHECK-NEXT:      j (OmpPrivate): HostAssoc
+!CHECK-NEXT:      k2 (OmpCriticalLock): Unknown
+program mn
+  integer :: j
+  j=2
+  !$omp parallel default(private)
+    !$omp critical(k2)
+    j=200
+    !$omp end critical(k2)
+  !$omp end parallel
+end 

Copy link
Contributor Author

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luporl You had some further comments in #112572 which makes me wonder whether I missed a point in this fix.

static bool IsPrivatizable(const Symbol *sym) {
auto *misc{sym->detailsIf<MiscDetails>()};
return !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
return IsVariableName(*sym) && !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole check can probably be simplified further in a separate patch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it should be OK to remove at least !IsNamedConstant(*sym), probably !IsProcedure(*sym) too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update in a separate patch.

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

When I looked at this I really didn't realize that the name was only identifying the critical construct.

@kiranchandramohan kiranchandramohan merged commit c952f0e into llvm:main Nov 28, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:openmp flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flang][OpenMP] assertion failure using default clause with critical

3 participants