diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index da6947a748fa..748604787c0f 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -3615,7 +3615,7 @@ void DeclarationVisitor::Post(const parser::CommonBlockObject &x) { bool DeclarationVisitor::Pre(const parser::EquivalenceStmt &x) { // save equivalence sets to be processed after specification part - CheckNotInBlock("EQUIVALENCE"); + CheckNotInBlock("EQUIVALENCE"); // C1107 for (const std::list &set : x.v) { equivalenceSets_.push_back(&set); } @@ -3656,12 +3656,8 @@ bool DeclarationVisitor::Pre(const parser::SaveStmt &x) { auto kind{std::get(y.t)}; const auto &name{std::get(y.t)}; if (kind == parser::SavedEntity::Kind::Common) { - if (currScope().kind() == Scope::Kind::Block) { - CheckNotInBlock("COMMON BLOCK NAME"); // C1107 - } else { - MakeCommonBlockSymbol(name); - AddSaveName(saveInfo_.commons, name.source); - } + MakeCommonBlockSymbol(name); + AddSaveName(saveInfo_.commons, name.source); } else { HandleAttributeStmt(Attr::SAVE, name); } @@ -3689,10 +3685,16 @@ void DeclarationVisitor::CheckSaveStmts() { for (const SourceName &name : saveInfo_.commons) { if (auto *symbol{currScope().FindCommonBlock(name)}) { auto &objects{symbol->get().objects()}; - if (objects.empty() && currScope().kind() != Scope::Kind::Block) { - Say(name, - "'%s' appears as a COMMON block in a SAVE statement but not in" - " a COMMON statement"_err_en_US); + if (objects.empty()) { + if (currScope().kind() != Scope::Kind::Block) { + Say(name, + "'%s' appears as a COMMON block in a SAVE statement but not in" + " a COMMON statement"_err_en_US); + } else { // C1108 + Say(name, + "'%s' specifier is not allowed in a BLOCK Construct." + " It is a Common Block Name"_err_en_US); + } } else { for (Symbol *object : symbol->get().objects()) { SetSaveAttr(*object); diff --git a/flang/test/semantics/blockconstruct02.f90 b/flang/test/semantics/blockconstruct02.f90 index b67169228e29..493cfd044be5 100644 --- a/flang/test/semantics/blockconstruct02.f90 +++ b/flang/test/semantics/blockconstruct02.f90 @@ -22,7 +22,7 @@ program main !ERROR: 'argmnt1' appears as a COMMON block in a SAVE statement but not in a COMMON statement save /argmnt1/ block - !ERROR: COMMON BLOCK NAME statement is not allowed in a BLOCK construct + !ERROR: 'argmnt2' specifier is not allowed in a BLOCK Construct. It is a Common Block Name save /argmnt2/ end block end program