[flang-commits] [flang] [Flang][OpenMP] Do not default privatize symbols that are not variables (PR #117886)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Wed Nov 27 06:18:31 PST 2024


https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/117886

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

Fixes #112572

>From dc1eaa8f68db0faac5a55616188b12c020dd4806 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Wed, 27 Nov 2024 14:09:08 +0000
Subject: [PATCH] [Flang][OpenMP] Do not default privatize symbols that are not
 variables

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

Fixes #112572
---
 flang/lib/Semantics/resolve-directives.cpp      |  2 +-
 .../OpenMP/critical_within_default.f90          | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/OpenMP/critical_within_default.f90

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 



More information about the flang-commits mailing list