[flang] Block containing an interface
authorV Donaldson <vdonaldson@nvidia.com>
Thu, 29 Jun 2023 17:58:05 +0000 (10:58 -0700)
committerV Donaldson <vdonaldson@nvidia.com>
Thu, 29 Jun 2023 20:25:45 +0000 (13:25 -0700)
Name mangling may be invoked for an interface procedure contained in
a block in a context that does not have access to block ID mapping.
Procedures can't be defined inside a block, so name mangling doesn't
need a block map. Relax an assert to account for this.

    block
      interface
        subroutine ss(n) bind(c)
          integer :: n
        end subroutine
      end interface
      call ss(5)
    end block
    end

flang/lib/Lower/Mangler.cpp
flang/test/Lower/block.f90

index ff1631c..e619277 100644 (file)
@@ -188,8 +188,9 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol,
 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<Fortran::semantics::SubprogramDetails>()) &&
          "block object mangling must specify a scopeBlockIdMap");
   ScopeBlockIdMap scopeBlockIdMap;
   return mangleName(symbol, scopeBlockIdMap, keepExternalInScope);
index 5a73a43..5341c73 100644 (file)
@@ -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<i32>
@@ -61,7 +62,6 @@ program bb ! block stack management and exits
     ! 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 @@ program bb ! block stack management and exits
       i = i + 1 ! 0 increments
 12  end block
 100 print*, i ! expect 21
+
+    ! CHECK: %[[V_51:[0-9]+]] = fir.call @llvm.stacksave() fastmath<contract> : () -> !fir.ref<i8>
+    ! CHECK: fir.store %c5{{.*}} to %[[V_0]] : !fir.ref<i32>
+    ! CHECK: fir.call @ss(%[[V_0]]) fastmath<contract> : (!fir.ref<i32>) -> ()
+    ! CHECK: fir.call @llvm.stackrestore(%[[V_51]]) fastmath<contract> : (!fir.ref<i8>) -> ()
+    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