Summary: If you create an expression with parse errors, the `parser::Expr.typedExpr` will be empty, which causes a compiler crash. The crash is caused by the check in check-do-forall.cpp that scans all expresssions to see if `DO` variables are being modified. It turned out that the problem was that I was fetching subexpressions of type `parser::Expr`, which are not guaranteed to have a non-null `typedExpr`. I fixed this by only grabbing the top-level expression from which to gather arguments as part of the DO loop analysis. This, in turn, exposed a problem where I wasn't collecting all of the actual arguments in an expression. This was caused by the fact that I wasn't recursing through the rest of the expression after finding an argument. I fixed this by recursing through the argument in the member function in `CollectActualArgumentsHelper`. Reviewers: klausler, tskeith, DavidTruby Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D81101
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
//===-- lib/Semantics/check-do-forall.h -------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef FORTRAN_SEMANTICS_CHECK_DO_FORALL_H_
|
|
#define FORTRAN_SEMANTICS_CHECK_DO_FORALL_H_
|
|
|
|
#include "flang/Common/idioms.h"
|
|
#include "flang/Semantics/semantics.h"
|
|
|
|
namespace Fortran::parser {
|
|
struct AssignmentStmt;
|
|
struct CallStmt;
|
|
struct ConnectSpec;
|
|
struct CycleStmt;
|
|
struct DoConstruct;
|
|
struct ExitStmt;
|
|
struct Expr;
|
|
struct ForallAssignmentStmt;
|
|
struct ForallConstruct;
|
|
struct ForallStmt;
|
|
struct InquireSpec;
|
|
struct IoControlSpec;
|
|
struct OutputImpliedDo;
|
|
struct StatVariable;
|
|
} // namespace Fortran::parser
|
|
|
|
namespace Fortran::semantics {
|
|
|
|
// To specify different statement types used in semantic checking.
|
|
ENUM_CLASS(StmtType, CYCLE, EXIT)
|
|
|
|
// Perform semantic checks on DO and FORALL constructs and statements.
|
|
class DoForallChecker : public virtual BaseChecker {
|
|
public:
|
|
explicit DoForallChecker(SemanticsContext &context) : context_{context} {}
|
|
void Leave(const parser::AssignmentStmt &);
|
|
void Leave(const parser::CallStmt &);
|
|
void Leave(const parser::ConnectSpec &);
|
|
void Enter(const parser::CycleStmt &);
|
|
void Enter(const parser::DoConstruct &);
|
|
void Leave(const parser::DoConstruct &);
|
|
void Enter(const parser::ForallConstruct &);
|
|
void Leave(const parser::ForallConstruct &);
|
|
void Enter(const parser::ForallStmt &);
|
|
void Leave(const parser::ForallStmt &);
|
|
void Leave(const parser::ForallAssignmentStmt &s);
|
|
void Enter(const parser::ExitStmt &);
|
|
void Enter(const parser::Expr &);
|
|
void Leave(const parser::Expr &);
|
|
void Leave(const parser::InquireSpec &);
|
|
void Leave(const parser::IoControlSpec &);
|
|
void Leave(const parser::OutputImpliedDo &);
|
|
void Leave(const parser::StatVariable &);
|
|
|
|
private:
|
|
SemanticsContext &context_;
|
|
int exprDepth_{0};
|
|
|
|
void SayBadLeave(
|
|
StmtType, const char *enclosingStmt, const ConstructNode &) const;
|
|
void CheckDoConcurrentExit(StmtType, const ConstructNode &) const;
|
|
void CheckForBadLeave(StmtType, const ConstructNode &) const;
|
|
void CheckNesting(StmtType, const parser::Name *) const;
|
|
};
|
|
} // namespace Fortran::semantics
|
|
#endif
|