[flang-commits] [flang] aa128bb - [flang] Catch misuse of a procedure designator as an output item

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sun Feb 12 16:45:08 PST 2023


Author: Peter Klausler
Date: 2023-02-12T16:44:58-08:00
New Revision: aa128bb21ee37ce07b02043fde57914d60ff2097

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

LOG: [flang] Catch misuse of a procedure designator as an output item

f18 was diagnosing the misuse of a procedure pointer as an output item,
but not the more general case of a procedure designator other than
a pointer.

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

Added: 
    

Modified: 
    flang/lib/Semantics/check-io.cpp
    flang/lib/Semantics/expression.cpp
    flang/test/Semantics/io04.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 349b34d7b811e..bbe76c4cc93a7 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -613,11 +613,9 @@ void IoChecker::Enter(const parser::OutputItem &item) {
       if (evaluate::IsBOZLiteral(*expr)) {
         context_.Say(parser::FindSourceLocation(*x), // C7109
             "Output item must not be a BOZ literal constant"_err_en_US);
-      }
-      const Symbol *last{GetLastSymbol(*expr)};
-      if (last && IsProcedurePointer(*last)) {
+      } else if (IsProcedure(*expr)) {
         context_.Say(parser::FindSourceLocation(*x),
-            "Output item must not be a procedure pointer"_err_en_US); // C1233
+            "Output item must not be a procedure"_err_en_US); // C1233
       }
       CheckForBadIoType(*expr,
           flags_.test(Flag::FmtOrNml)

diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 116aa7f1504e5..6eb08893129ed 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -566,10 +566,10 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Designator &d) {
     std::optional<DataRef> dataRef{ExtractDataRef(std::move(result))};
     if (!dataRef) {
       dataRef = ExtractDataRef(std::move(result), /*intoSubstring=*/true);
-      if (!dataRef) {
-        dataRef = ExtractDataRef(std::move(result),
-            /*intoSubstring=*/false, /*intoComplexPart=*/true);
-      }
+    }
+    if (!dataRef) {
+      dataRef = ExtractDataRef(std::move(result),
+          /*intoSubstring=*/false, /*intoComplexPart=*/true);
     }
     if (dataRef && !CheckDataRef(*dataRef)) {
       result.reset();

diff  --git a/flang/test/Semantics/io04.f90 b/flang/test/Semantics/io04.f90
index 92601193365c4..685e43dd6e401 100644
--- a/flang/test/Semantics/io04.f90
+++ b/flang/test/Semantics/io04.f90
@@ -12,6 +12,8 @@
   integer, pointer :: a(:)
   integer, parameter :: const_id = 66666
   procedure(), pointer :: procptr
+  external external
+  intrinsic acos
 
   namelist /nnn/ nn1, nn2
 
@@ -134,8 +136,12 @@
 
   write(*, '(X)')
 
-  !ERROR: Output item must not be a procedure pointer
-  print*, n1, procptr, n2
+  !ERROR: Output item must not be a procedure
+  print*, procptr
+  !ERROR: Output item must not be a procedure
+  print*, acos
+  !ERROR: Output item must not be a procedure
+  print*, external
 
 1 format (A)
 9 continue


        


More information about the flang-commits mailing list