[flang-commits] [flang] 1457eb3 - [flang] Check C854, C855, & C856 on PROTECTED entities

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Dec 17 10:19:04 PST 2022


Author: Peter Klausler
Date: 2022-12-17T09:47:21-08:00
New Revision: 1457eb378aa8c4b69491b62fef0e523c7c690158

URL: https://github.com/llvm/llvm-project/commit/1457eb378aa8c4b69491b62fef0e523c7c690158
DIFF: https://github.com/llvm/llvm-project/commit/1457eb378aa8c4b69491b62fef0e523c7c690158.diff

LOG: [flang] Check C854, C855, & C856 on PROTECTED entities

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

Differential Revision: https://reviews.llvm.org/D140150

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index f6a7f4e5d154..f9eab21aeb02 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -251,6 +251,20 @@ void CheckHelper::Check(const Symbol &symbol) {
   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);
   }

diff  --git a/flang/test/Semantics/resolve82.f90 b/flang/test/Semantics/resolve82.f90
index 69cf407884c2..99c0f4120218 100644
--- a/flang/test/Semantics/resolve82.f90
+++ b/flang/test/Semantics/resolve82.f90
@@ -23,6 +23,17 @@ end function procFunc
   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 @@ subroutine testProcDecl(arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11)
       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


        


More information about the flang-commits mailing list