[flang-commits] [flang] 1036d78 - [flang][lowering] lowering assigned goto of allocatable variable (#175874)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 22 08:58:16 PST 2026


Author: Andre Kuhlenschmidt
Date: 2026-01-22T16:58:10Z
New Revision: 1036d782ae83b37578d6a810544a30f7453b79e9

URL: https://github.com/llvm/llvm-project/commit/1036d782ae83b37578d6a810544a30f7453b79e9
DIFF: https://github.com/llvm/llvm-project/commit/1036d782ae83b37578d6a810544a30f7453b79e9.diff

LOG: [flang][lowering] lowering assigned goto of allocatable variable (#175874)

towards [#173594](https://github.com/llvm/llvm-project/issues/173594)

This PR adds a lowering for `AssignedGoto`s that reference an
allocatable variable.

Added: 
    

Modified: 
    flang/lib/Lower/Bridge.cpp
    flang/test/Lower/assigned-goto.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 251e8d9ca9e14..5eefd5472e143 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2133,8 +2133,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
       }
     }
     if (!labelList.empty()) {
-      auto selectExpr =
-          fir::LoadOp::create(*builder, loc, getSymbolAddress(symbol));
+      mlir::Value selectExpr = hlfir::loadTrivialScalar(
+          loc, *builder, hlfir::Entity{getSymbolAddress(symbol)});
       // Add a default error target in case the goto is nonconforming.
       mlir::Block *errorBlock =
           builder->getBlock()->splitBlock(builder->getInsertionPoint());

diff  --git a/flang/test/Lower/assigned-goto.f90 b/flang/test/Lower/assigned-goto.f90
index 4184839337de1..15bc8a9c95962 100644
--- a/flang/test/Lower/assigned-goto.f90
+++ b/flang/test/Lower/assigned-goto.f90
@@ -35,6 +35,26 @@ subroutine list
  42 print*, 300, V
  end
 
+ subroutine allocated
+    integer, allocatable :: L
+    integer :: V
+ 13 V = 1
+    allocate(L)
+    ! CHECK: %[[N0:.+]] = fir.box_addr %{{.+}}
+    ! CHECK: fir.store %c31{{.*}} to %[[N0]]
+    assign 31 to L
+    ! CHECK: %[[N1:.+]] = fir.box_addr %{{.+}}
+    ! CHECK: %[[N2:.+]] = fir.load %[[N1]]
+    ! CHECK: fir.select %[[N2]] : i32 [31, ^bb{{.}}, unit, ^bb{{.}}]
+    ! CHECK: fir.call @_FortranAReportFatalUserError
+    goto L
+ 23 V = 2
+    goto 41
+ 31 V = 3
+ 41 print*, 3, V
+ end subroutine allocated
+
     call nolist
     call list
+    call allocated
  end


        


More information about the flang-commits mailing list