Skip to content

Commit

Permalink
[flang] Check that DO index variables are definable
Browse files Browse the repository at this point in the history
We're letting immutable objects appear as DO index variables;
catch and diagnose this error.

Differential Revision: https://reviews.llvm.org/D142767
  • Loading branch information
klausler committed Jan 29, 2023
1 parent fd9f42f commit 2725499
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flang/lib/Semantics/check-do-forall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Semantics/definable03.f90
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2725499

Please sign in to comment.