Index: flang/lib/Semantics/resolve-labels.cpp =================================================================== --- flang/lib/Semantics/resolve-labels.cpp +++ flang/lib/Semantics/resolve-labels.cpp @@ -233,13 +233,16 @@ using LabeledConstructEndStmts = std::tuple; + parser::EndIfStmt, parser::EndWhereStmt>; using LabeledProgramUnitEndStmts = std::tuple; auto targetFlags{ConstructBranchTargetFlags(statement)}; if constexpr (common::HasMember) { AddTargetLabelDefinition(label.value(), targetFlags, ParentScope()); + } else if constexpr (std::is_same_v) { + // the label on an END SELECT is not in the last case + AddTargetLabelDefinition(label.value(), targetFlags, ParentScope(), true); } else if constexpr (common::HasMember) { constexpr bool isExecutableConstructEndStmt{true}; AddTargetLabelDefinition(label.value(), targetFlags, currentScope_, @@ -286,19 +289,23 @@ bool Pre(const parser::CaseConstruct &caseConstruct) { return PushConstructName(caseConstruct); } + void Post(const parser::SelectCaseStmt &) { PushScope(); } bool Pre(const parser::CaseConstruct::Case &) { return SwitchToNewScope(); } bool Pre(const parser::SelectRankConstruct &selectRankConstruct) { return PushConstructName(selectRankConstruct); } + void Post(const parser::SelectRankStmt &) { PushScope(); } bool Pre(const parser::SelectRankConstruct::RankCase &) { return SwitchToNewScope(); } bool Pre(const parser::SelectTypeConstruct &selectTypeConstruct) { return PushConstructName(selectTypeConstruct); } + void Post(const parser::SelectTypeStmt &) { PushScope(); } bool Pre(const parser::SelectTypeConstruct::TypeCase &) { return SwitchToNewScope(); } + void Post(const parser::EndSelectStmt &) { PopScope(); } bool Pre(const parser::WhereConstruct &whereConstruct) { return PushConstructName(whereConstruct); } @@ -994,7 +1001,7 @@ context.Say(position, isFatal ? "Label '%u' is in a construct that prevents its use as a branch target here"_err_en_US - : "Label '%u' is in a construct that prevents its use as a branch target here"_en_US, + : "Label '%u' is in a construct that should not be used as a branch target here"_warn_en_US, SayLabel(label)); } } Index: flang/test/Semantics/label05.f90 =================================================================== --- flang/test/Semantics/label05.f90 +++ flang/test/Semantics/label05.f90 @@ -1,7 +1,6 @@ ! RUN: not %flang_fc1 -fdebug-unparse-with-symbols %s 2>&1 | FileCheck %s ! CHECK: Label '50' was not found -! CHECK-NOT: error: Label '55' is in a construct that prevents its use as a branch target here -! CHECK: Label '55' is in a construct that prevents its use as a branch target here +! CHECK: warning: Label '55' is in a construct that should not be used as a branch target here ! CHECK: Label '70' is not a branch target ! CHECK: Control flow use of '70' ! CHECK: error: Label '80' is in a construct that prevents its use as a branch target here Index: flang/test/Semantics/label06.f90 =================================================================== --- flang/test/Semantics/label06.f90 +++ flang/test/Semantics/label06.f90 @@ -1,10 +1,10 @@ ! RUN: not %flang_fc1 -fdebug-unparse-with-symbols %s 2>&1 | FileCheck %s -! CHECK: Label '10' is in a construct that prevents its use as a branch target here +! CHECK: warning: Label '10' is in a construct that should not be used as a branch target here ! CHECK: Label '20' was not found ! CHECK: Label '30' is not a branch target ! CHECK: Control flow use of '30' -! CHECK: Label '40' is in a construct that prevents its use as a branch target here -! CHECK: Label '50' is in a construct that prevents its use as a branch target here +! CHECK: warning: Label '40' is in a construct that should not be used as a branch target here +! CHECK: warning: Label '50' is in a construct that should not be used as a branch target here subroutine sub00(n) GOTO (10,20,30) n Index: flang/test/Semantics/label07.f90 =================================================================== --- flang/test/Semantics/label07.f90 +++ flang/test/Semantics/label07.f90 @@ -1,7 +1,7 @@ ! RUN: not %flang_fc1 -fdebug-unparse-with-symbols %s 2>&1 | FileCheck %s ! CHECK: Label '30' is not a branch target ! CHECK: Control flow use of '30' -! CHECK: Label '10' is in a construct that prevents its use as a branch target here +! CHECK: warning: Label '10' is in a construct that should not be used as a branch target here ! CHECK: Label '20' was not found ! CHECK: Label '60' was not found