Index: flang/lib/Semantics/resolve-names.cpp =================================================================== --- flang/lib/Semantics/resolve-names.cpp +++ flang/lib/Semantics/resolve-names.cpp @@ -559,6 +559,14 @@ return *derivedType; } } + } else if constexpr (std::is_same_v) { + if (isSameSymbolNameAllowed(*symbol, details)) { + symbol = &MakeSymbol(name, attrs); + if (symbol->CanReplaceDetails(details)) { + symbol->set_details(std::move(details)); + } + return *symbol; + } } if (symbol->CanReplaceDetails(details)) { // update the existing symbol @@ -603,6 +611,13 @@ void NotePossibleBadForwardRef(const parser::Name &); std::optional HadForwardRef(const Symbol &) const; bool CheckPossibleBadForwardRef(const Symbol &); + bool isSameSymbolNameAllowed(Symbol &symbol, MiscDetails details) { + if (details.kind() == MiscDetails::Kind::ConstructName && + symbol.has()) { + return true; + } + return false; + } bool inExecutionPart_{false}; bool inSpecificationPart_{false}; Index: flang/test/Semantics/resolve35.f90 =================================================================== --- flang/test/Semantics/resolve35.f90 +++ flang/test/Semantics/resolve35.f90 @@ -3,6 +3,13 @@ subroutine s1 real :: foo + foo: block + end block foo +end + +subroutine s1b + foo: block + end block foo !ERROR: 'foo' is already declared in this scoping unit foo: block end block foo @@ -17,6 +24,12 @@ end do foo end +subroutine s2b(x) + logical :: x + x: if (x) then + end if x +end + subroutine s3 real :: a(10,10), b(10,10) type y; end type