[flang-commits] [flang] [flang] Don't duplicate impure function call for UBOUND() (PR #153648)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Thu Aug 14 13:15:42 PDT 2025


================
@@ -0,0 +1,18 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+! Ensure that UBOUND() calculation from LBOUND()+SIZE() isn't applied to
+! variables containing references to impure functions.
+type t
+  real, allocatable :: a(:)
+end type
+interface
+  pure integer function pure(n)
+    integer, intent(in) :: n
+  end
+end interface
+type(t) :: x(10)
+allocate(x(1)%a(2))
+!CHECK: PRINT *, ubound(x(int(impure(1_4),kind=8))%a,dim=1_4)
+print *, ubound(x(impure(1))%a, dim=1)
+!CHECK: PRINT *, int(size(x(int(pure(1_4),kind=8))%a,dim=1,kind=8)+lbound(x(int(pure(1_4),kind=8))%a,dim=1,kind=8)-1_8,kind=4)
----------------
eugeneepshteyn wrote:

Ok, so because it's PURE, it's ok to call it multiple times with the same value, because it's supposed to produce the same results on the same inputs. (And there's no way in Fortran to check how many times it's called without making it impure :-) )


https://github.com/llvm/llvm-project/pull/153648


More information about the flang-commits mailing list