[flang-commits] [flang] 2725499 - [flang] Check that DO index variables are definable

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sun Jan 29 14:27:36 PST 2023


Author: Peter Klausler
Date: 2023-01-29T14:27:26-08:00
New Revision: 2725499221c93247cd91ea734ee6b4e022727a63

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

LOG: [flang] Check that DO index variables are definable

We're letting immutable objects appear as DO index variables;
catch and diagnose this error.

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

Added: 
    flang/test/Semantics/definable03.f90

Modified: 
    flang/lib/Semantics/check-do-forall.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index 3af15a68fd83..65b2986139b4 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "check-do-forall.h"
+#include "definable.h"
 #include "flang/Common/template.h"
 #include "flang/Evaluate/call.h"
 #include "flang/Evaluate/expression.h"
@@ -486,6 +487,14 @@ class DoContext {
       if (!IsVariableName(*symbol)) {
         context_.Say(
             sourceLocation, "DO control must be an INTEGER variable"_err_en_US);
+      } else if (auto why{WhyNotDefinable(sourceLocation,
+                     context_.FindScope(sourceLocation), DefinabilityFlags{},
+                     *symbol)}) {
+        context_
+            .Say(sourceLocation,
+                "'%s' may not be used as a DO variable"_err_en_US,
+                symbol->name())
+            .Attach(std::move(*why));
       } else {
         const DeclTypeSpec *symType{symbol->GetType()};
         if (!symType) {

diff  --git a/flang/test/Semantics/definable03.f90 b/flang/test/Semantics/definable03.f90
new file mode 100644
index 000000000000..736a22fa3e5f
--- /dev/null
+++ b/flang/test/Semantics/definable03.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+subroutine sub(j)
+  integer, intent(in) :: j
+  !ERROR: 'j' may not be used as a DO variable
+  !BECAUSE: 'j' is an INTENT(IN) dummy argument
+  do j = 1, 10
+  end do
+end


        


More information about the flang-commits mailing list