[flang-commits] [flang] [flang][OpenMP] Fix the attribute setting for OmpCommonBlock (PR #73676)

via flang-commits flang-commits at lists.llvm.org
Tue Nov 28 09:49:13 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Shraiysh (shraiysh)

<details>
<summary>Changes</summary>

This patch sets the `OmpCommonBlock` attribute everytime a common block object is resolved in openmp context. Also, removed the call to `CheckMultipleAppearances(.., OmpCommonBlock)` because that is simply not required - we need to check multiple apprearances for the directive or clause related flag and not for the the common block flag.

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


4 Files Affected:

- (modified) flang/lib/Semantics/resolve-directives.cpp (+9-11) 
- (modified) flang/test/Semantics/OpenMP/common-block.f90 (+1-1) 
- (modified) flang/test/Semantics/OpenMP/declare-target-common-block.f90 (+1-1) 
- (modified) flang/test/Semantics/OpenMP/symbol01.f90 (+1-1) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index da6c865ad56a3b1..93eac44c25e3f77 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1989,16 +1989,15 @@ Symbol *OmpAttributeVisitor::ResolveOmpCommonBlockName(
     return nullptr;
   }
   // First check if the Common Block is declared in the current scope
-  if (auto *cur{GetContext().scope.FindCommonBlock(name->source)}) {
-    name->symbol = cur;
-    return cur;
-  }
+  Symbol *sym = GetContext().scope.FindCommonBlock(name->source);
   // Then check parent scope
-  if (auto *prev{GetContext().scope.parent().FindCommonBlock(name->source)}) {
-    name->symbol = prev;
-    return prev;
-  }
-  return nullptr;
+  if (!sym)
+    sym = GetContext().scope.parent().FindCommonBlock(name->source);
+  if (!sym)
+    return nullptr;
+  sym->set(Symbol::Flag::OmpCommonBlock);
+  name->symbol = sym;
+  return sym;
 }
 
 // Use this function over ResolveOmpName when an omp object's scope needs
@@ -2152,8 +2151,7 @@ void OmpAttributeVisitor::ResolveOmpObject(
           [&](const parser::Name &name) { // common block
             if (auto *symbol{ResolveOmpCommonBlockName(&name)}) {
               if (!dataCopyingAttributeFlags.test(ompFlag)) {
-                CheckMultipleAppearances(
-                    name, *symbol, Symbol::Flag::OmpCommonBlock);
+                CheckMultipleAppearances(name, *symbol, ompFlag);
               }
               // 2.15.3 When a named common block appears in a list, it has the
               // same meaning as if every explicit member of the common block
diff --git a/flang/test/Semantics/OpenMP/common-block.f90 b/flang/test/Semantics/OpenMP/common-block.f90
index e1ddd120da857b5..63b25e86d05f9be 100644
--- a/flang/test/Semantics/OpenMP/common-block.f90
+++ b/flang/test/Semantics/OpenMP/common-block.f90
@@ -4,7 +4,7 @@ program main
   !CHECK: a size=4 offset=0: ObjectEntity type: REAL(4)
   !CHECK: b size=8 offset=4: ObjectEntity type: INTEGER(4) shape: 1_8:2_8
   !CHECK: c size=4 offset=12: ObjectEntity type: REAL(4)
-  !CHECK: blk size=16 offset=0: CommonBlockDetails alignment=4: a b c
+  !CHECK: blk (OmpCommonBlock) size=16 offset=0: CommonBlockDetails alignment=4: a b c
   real :: a, c
   integer :: b(2)
   common /blk/ a, b, c
diff --git a/flang/test/Semantics/OpenMP/declare-target-common-block.f90 b/flang/test/Semantics/OpenMP/declare-target-common-block.f90
index 33a093a03a22763..f8c7fd6ac7f2698 100644
--- a/flang/test/Semantics/OpenMP/declare-target-common-block.f90
+++ b/flang/test/Semantics/OpenMP/declare-target-common-block.f90
@@ -3,7 +3,7 @@
 PROGRAM main
     !CHECK: one (OmpDeclareTarget) size=4 offset=0: ObjectEntity type: REAL(4)
     !CHECK: two (OmpDeclareTarget) size=4 offset=4: ObjectEntity type: REAL(4)
-    !CHECK: numbers size=8 offset=0: CommonBlockDetails alignment=4: one two
+    !CHECK: numbers (OmpCommonBlock) size=8 offset=0: CommonBlockDetails alignment=4: one two
     REAL :: one, two
     COMMON /numbers/ one, two
     !$omp declare target(/numbers/)
diff --git a/flang/test/Semantics/OpenMP/symbol01.f90 b/flang/test/Semantics/OpenMP/symbol01.f90
index 0b435a9ab9850b3..98d8bddbaf2fed1 100644
--- a/flang/test/Semantics/OpenMP/symbol01.f90
+++ b/flang/test/Semantics/OpenMP/symbol01.f90
@@ -20,7 +20,7 @@ end module md
 program mm
  !REF: /md
  use :: md
- !DEF: /mm/c CommonBlockDetails
+ !DEF: /mm/c (OmpCommonBlock) CommonBlockDetails
  !DEF: /mm/x ObjectEntity REAL(4)
  !DEF: /mm/y ObjectEntity REAL(4)
  common /c/x, y

``````````

</details>


https://github.com/llvm/llvm-project/pull/73676


More information about the flang-commits mailing list