[flang-commits] [flang] 2b12d83 - [flang] Block containing an interface

V Donaldson via flang-commits flang-commits at lists.llvm.org
Thu Jun 29 13:26:20 PDT 2023


Author: V Donaldson
Date: 2023-06-29T13:25:45-07:00
New Revision: 2b12d8350eaaa4f07311526b9cf8976ac1a4564a

URL: https://github.com/llvm/llvm-project/commit/2b12d8350eaaa4f07311526b9cf8976ac1a4564a
DIFF: https://github.com/llvm/llvm-project/commit/2b12d8350eaaa4f07311526b9cf8976ac1a4564a.diff

LOG: [flang] Block containing an interface

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index ff1631c6929ab4..e61927781e5736 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -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);

diff  --git a/flang/test/Lower/block.f90 b/flang/test/Lower/block.f90
index 5a73a43eb50fb5..5341c731230ad6 100644
--- a/flang/test/Lower/block.f90
+++ b/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<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


        


More information about the flang-commits mailing list