From 5597f366e1ae4f13d1a6ef18bd97c104c0ab20ae Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Mon, 8 Jul 2019 09:19:07 -0700 Subject: [PATCH] [flang] Fix issues 518 and 546 - Only allow out-of-scope label target for label-do-stmt when the label is on an end-stmt of a scope directly nested into the one of the label-do-stmt. - Also transform label-do-stmt into non-label-do constructs so that later phases do not have to handle label-do-stmt. Original-commit: flang-compiler/f18@91cff2f29698506ac95138107c5f0c625fa237ba Reviewed-on: https://github.com/flang-compiler/f18/pull/552 Tree-same-pre-rewrite: false --- flang/lib/semantics/canonicalize-do.cc | 24 +++++++++++++++ flang/lib/semantics/resolve-labels.cc | 41 +++++++++++++++++++++----- flang/test/semantics/label14.f90 | 34 +++++++++++++++++++++ 3 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 flang/test/semantics/label14.f90 diff --git a/flang/lib/semantics/canonicalize-do.cc b/flang/lib/semantics/canonicalize-do.cc index ba2a726ad649..9f70fbfc0af4 100644 --- a/flang/lib/semantics/canonicalize-do.cc +++ b/flang/lib/semantics/canonicalize-do.cc @@ -33,6 +33,30 @@ public: std::visit( common::visitors{ [](auto &) {}, + // Labels on end-stmt of constructs are accepted by f18 for + // compatibility purposes, even-though they are technically + // not in the same scope as the label-do-stmt. + [&](common::Indirection &ifConstruct) { + CanonicalizeIfMatch(block, stack, i, + std::get>(ifConstruct.value().t)); + }, + [&](common::Indirection &doConstruct) { + CanonicalizeIfMatch(block, stack, i, + std::get>(doConstruct.value().t)); + }, + [&](common::Indirection &caseConstruct) { + CanonicalizeIfMatch(block, stack, i, + std::get>( + caseConstruct.value().t)); + }, + [&](common::Indirection &selectRank) { + CanonicalizeIfMatch(block, stack, i, + std::get>(selectRank.value().t)); + }, + [&](common::Indirection &selectType) { + CanonicalizeIfMatch(block, stack, i, + std::get>(selectType.value().t)); + }, [&](Statement> &labelDoStmt) { auto &label{std::get