Index: flang/lib/Lower/Mangler.cpp =================================================================== --- flang/lib/Lower/Mangler.cpp +++ flang/lib/Lower/Mangler.cpp @@ -188,8 +188,9 @@ std::string Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol, bool keepExternalInScope) { - assert(symbol.owner().kind() != - Fortran::semantics::Scope::Kind::BlockConstruct && + assert((symbol.owner().kind() != + Fortran::semantics::Scope::Kind::BlockConstruct || + symbol.has()) && "block object mangling must specify a scopeBlockIdMap"); ScopeBlockIdMap scopeBlockIdMap; return mangleName(symbol, scopeBlockIdMap, keepExternalInScope); Index: flang/test/Lower/block.f90 =================================================================== --- flang/test/Lower/block.f90 +++ flang/test/Lower/block.f90 @@ -2,6 +2,7 @@ ! CHECK-LABEL: func @_QQmain program bb ! block stack management and exits + ! CHECK: %[[V_0:[0-9]+]] = fir.alloca i32 {adapt.valuebyref} ! CHECK: %[[V_1:[0-9]+]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} integer :: i, j ! CHECK: fir.store %c0{{.*}} to %[[V_1]] : !fir.ref @@ -61,7 +62,6 @@ ! CHECK: fir.call @llvm.stackrestore(%[[V_3]]) ! CHECK: br ^bb19 ! CHECK: ^bb19: // 2 preds: ^bb13, ^bb18 - ! CHECK: return block i = i + 1 ! 1 increment do j = 1, 5 @@ -78,4 +78,21 @@ i = i + 1 ! 0 increments 12 end block 100 print*, i ! expect 21 + + ! CHECK: %[[V_51:[0-9]+]] = fir.call @llvm.stacksave() fastmath : () -> !fir.ref + ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref + ! CHECK: fir.call @ss(%[[V_0]]) fastmath : (!fir.ref) -> () + ! CHECK: fir.call @llvm.stackrestore(%[[V_51]]) fastmath : (!fir.ref) -> () + block + interface + subroutine ss(n) bind(c) + integer :: n + end subroutine + end interface + call ss(5) + end block end + +subroutine ss(n) bind(c) + print*, n +end subroutine