[flang] [OpenMP] add common block example
authorJinxin Yang <jinxiny@nvidia.com>
Mon, 16 Sep 2019 06:08:29 +0000 (23:08 -0700)
committerJinxin (Brian) Yang <brianyang1106@gmail.com>
Fri, 25 Oct 2019 22:16:20 +0000 (15:16 -0700)
Original-commit: flang-compiler/f18@a4c923e848bd55adc734808dbc019951610c29e6

flang/lib/semantics/resolve-names.cc
flang/test/semantics/CMakeLists.txt
flang/test/semantics/omp-resolve03.f90 [new file with mode: 0644]

index 9e6f14a..e39ebbd 100644 (file)
@@ -1162,7 +1162,7 @@ void OmpVisitor::ResolveOmpObject(
     } else {
       Say(designator.source,  // 2.15.3
           "COMMON block must be declared in the same scoping unit "
-          "in which the directive or clause appears"_err_en_US);
+          "in which the OpenMP directive or clause appears"_err_en_US);
     }
   }
 }
index 07f8a22..08a2c73 100644 (file)
@@ -156,6 +156,7 @@ set(ERROR_TESTS
   null01.f90
   omp-resolve01.f90
   omp-resolve02.f90
+  omp-resolve03.f90
   omp-symbol01.f90
   omp-symbol02.f90
   omp-symbol03.f90
@@ -293,7 +294,7 @@ foreach(test ${MODFILE_TESTS})
     COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_modfile.sh ${test} ${F18})
 endforeach()
 
-foreach(test ${LABEL_TESTS} ${CANONDO_TESTS} ${DOCONCURRENT_TESTS} 
+foreach(test ${LABEL_TESTS} ${CANONDO_TESTS} ${DOCONCURRENT_TESTS}
              ${FORALL_TESTS} ${GETSYMBOLS_TESTS} ${GETDEFINITION_TESTS})
   add_test(NAME ${test}
     COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_any.sh ${test} ${F18})
diff --git a/flang/test/semantics/omp-resolve03.f90 b/flang/test/semantics/omp-resolve03.f90
new file mode 100644 (file)
index 0000000..e476f23
--- /dev/null
@@ -0,0 +1,36 @@
+! Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.
+!
+! Licensed under the Apache License, Version 2.0 (the "License");
+! you may not use this file except in compliance with the License.
+! You may obtain a copy of the License at
+!
+!     http://www.apache.org/licenses/LICENSE-2.0
+!
+! Unless required by applicable law or agreed to in writing, software
+! distributed under the License is distributed on an "AS IS" BASIS,
+! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+! See the License for the specific language governing permissions and
+! limitations under the License.
+
+!OPTIONS: -fopenmp
+
+! 2.15.3 Although variables in common blocks can be accessed by use association
+! or host association, common block names cannot. As a result, a common block
+! name specified in a data-sharing attribute clause must be declared to be a
+! common block in the same scoping unit in which the data-sharing attribute
+! clause appears.
+
+  common /c/ a, b
+  integer a(3), b
+
+  A = 1
+  B = 2
+  block
+    !ERROR: COMMON block must be declared in the same scoping unit in which the OpenMP directive or clause appears
+    !$omp parallel shared(/c/)
+    a(1:2) = 3
+    B = 4
+    !$omp end parallel
+  end block
+  print *, a, b
+end