[flang-commits] [PATCH] D140150: [flang] Check C854, C855, & C856 on PROTECTED entities

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Dec 15 12:11:23 PST 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

Check for things that are not allowed to bear the PROTECTED
attribute.


https://reviews.llvm.org/D140150

Files:
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Semantics/resolve82.f90


Index: flang/test/Semantics/resolve82.f90
===================================================================
--- flang/test/Semantics/resolve82.f90
+++ flang/test/Semantics/resolve82.f90
@@ -23,6 +23,17 @@
   procedure(procFunc), bind(c), pointer, bind(c) :: proc3
   !WARNING: Attribute 'PROTECTED' cannot be used more than once
   procedure(procFunc), protected, pointer, protected :: proc4
+  !ERROR: A PROTECTED entity must be a variable or pointer
+  external extsub
+  protected extsub
+  real x
+  !ERROR: A PROTECTED entity must be a variable or pointer
+  namelist /nml/ x
+  protected nml
+  !ERROR: A PROTECTED entity may not be in a common block
+  real y
+  common /blk/ y
+  protected y
 
 contains
 
@@ -43,6 +54,9 @@
       procedure(procFunc), pointer, optional, pointer :: arg10
       !WARNING: Attribute 'SAVE' cannot be used more than once
       procedure(procFunc), save, pointer, save :: localProc
+      !ERROR: A PROTECTED entity must be in the specification part of a module
+      real x
+      protected x
     end subroutine testProcDecl
 
 end module m
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -251,6 +251,20 @@
   if (isDone) {
     return; // following checks do not apply
   }
+  if (symbol.attrs().test(Attr::PROTECTED)) {
+    if (symbol.owner().kind() != Scope::Kind::Module) { // C854
+      messages_.Say(
+          "A PROTECTED entity must be in the specification part of a module"_err_en_US);
+    }
+    if (!evaluate::IsVariable(symbol) && !IsProcedurePointer(symbol)) { // C855
+      messages_.Say(
+          "A PROTECTED entity must be a variable or pointer"_err_en_US);
+    }
+    if (InCommonBlock(symbol)) { // C856
+      messages_.Say(
+          "A PROTECTED entity may not be in a common block"_err_en_US);
+    }
+  }
   if (IsPointer(symbol)) {
     CheckPointer(symbol);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140150.483291.patch
Type: text/x-patch
Size: 2010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221215/c02e0db7/attachment.bin>


More information about the flang-commits mailing list