# Allocated array bounds with MOLD and SOURCE on expressions

**URL:** https://fortran-lang.discourse.group/t/allocated-array-bounds-with-mold-and-source-on-expressions/3032
**Category:** Uncategorized
**Created:** [March 23, 2022, 1:03pm UTC](https://fortran-lang.discourse.group/t/allocated-array-bounds-with-mold-and-source-on-expressions/3032 "2022-03-23T13:03:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)
#### Post date: [March 23, 2022, 1:03pm UTC](https://fortran-lang.discourse.group/t/allocated-array-bounds-with-mold-and-source-on-expressions/3032/1 "2022-03-23T13:03:21Z")

</div>

Gfortran, Intel Fortran, and flang are giving different results for the lower bounds of an array when it is allocated with source or mold. I think gfortran is correct, since parenthesizing an array or multiplying it by 1 creates an expression, and expressions have lower bounds of 1. For the code

```auto
program alloc
implicit none
integer, parameter :: n = 2
real :: x(2:2+n-1)
real, allocatable :: y(:)
character (len=*), parameter :: nl = new_line("")
call random_number(x)
print*,"x =",x
print*,"lbound(x),lbound((x)),lbound(1*x)=",lbound(x),lbound((x)),lbound(1*x)
allocate (y(n))
print*,nl,"allocate(y(n)), y =",y ; deallocate (y)
allocate (y,mold=x)
print*,nl,"allocate(y,mold=x) y =",y
print*,"lbound(y)=",lbound(y)
deallocate (y) ; allocate (y,mold=(x))
print*,nl,"allocate(y,mold=(x)) y =",y
print*,"lbound(y)=",lbound(y)
deallocate (y) ; allocate (y,mold=1*x)
print*,nl,"allocate(y,mold=1*x) y =",y
print*,"lbound(y)=",lbound(y)
deallocate (y) ; allocate (y,source=x)
print*,nl,"allocate (y,source=x) y =",y
print*,"lbound(y)=",lbound(y)
deallocate (y) ; allocate (y, source = (x))
print*,nl,"allocate (y,source=(x)) y =",y
print*,"lbound(y)=",lbound(y)
deallocate (y) ; allocate (y, source = 1*x)
print*,nl,"allocate (y,source=1*x) y =",y
print*,"lbound(y)=",lbound(y)
y = [x,1.0]
! allocation on assignment allowed on allocated target
print*,nl,"y = [x,1.0] =",y 
end program alloc

```

gfortran gives

```auto
 x = 0.507174253 0.208649397    
 lbound(x),lbound((x)),lbound(1*x)= 2 1 1
 
allocate(y(n)), y = -3.74480805E-06 7.41286888E-43
 
allocate(y,mold=x) y = -3.74481533E-06 7.41286888E-43
 lbound(y)= 2
 
allocate(y,mold=(x)) y = -3.74481533E-06 7.41286888E-43
 lbound(y)= 1
 
allocate(y,mold=1*x) y = -3.74481533E-06 7.41286888E-43
 lbound(y)= 1
 
allocate (y,source=x) y = 0.507174253 0.208649397    
 lbound(y)= 2
 
allocate (y,source=(x)) y = 0.507174253 0.208649397    
 lbound(y)= 1
 
allocate (y,source=1*x) y = 0.507174253 0.208649397    
 lbound(y)= 1
 
y = [x,1.0] = 0.507174253 0.208649397 1.00000000

```

ifort on Windows Version 2021.5.0 Build 20211109\_000000 gives

```auto
 x = 3.9208680E-07 2.5480442E-02
 lbound(x),lbound((x)),lbound(1*x)= 2 1 1
 
allocate(y(n)), y = 6.3367669E-39 7.0714481E-39
 
allocate(y,mold=x) y = 1.0660544E+27 1.6651776E+25
 lbound(y)= 2
 
allocate(y,mold=(x)) y = 4.0461097E-14 1.8053905E+28
 lbound(y)= 2
 
allocate(y,mold=1*x) y = 3.0097508E+32 7.9316175E+34
 lbound(y)= 1
 
allocate (y,source=x) y = 3.9208680E-07 2.5480442E-02
 lbound(y)= 2
 
allocate (y,source=(x)) y = 3.9208680E-07 2.5480442E-02
 lbound(y)= 2
 
allocate (y,source=1*x) y = 3.9208680E-07 2.5480442E-02
 lbound(y)= 1
 
y = [x,1.0] = 3.9208680E-07 2.5480442E-02 1.000000

```

flang clang version 7.0.1 gives

```auto
     x = 0.9079230 0.1906921
 lbound(x),lbound((x)),lbound(1*x)= 2 2 1

allocate(y(n)), y = 0.000000 0.000000

allocate(y,mold=x) y = 0.000000 0.000000
 lbound(y)= 2

allocate(y,mold=(x)) y = 0.000000 0.000000
 lbound(y)= 2

allocate(y,mold=1*x) y = 0.000000 0.000000
 lbound(y)= 2

allocate (y,source=x) y = 0.9079230 0.1906921
 lbound(y)= 2

allocate (y,source=(x)) y = 0.9079230 0.1906921
 lbound(y)= 2

allocate (y,source=1*x) y = 0.9079230 0.1906921
 lbound(y)= 2

y = [x,1.0] = 0.9079230 0.1906921 1.000000

```

---

<div class="post-metadata">

### Author: ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)
#### Post date: [March 23, 2022, 3:23pm UTC](https://fortran-lang.discourse.group/t/allocated-array-bounds-with-mold-and-source-on-expressions/3032/2 "2022-03-23T15:23:14Z")

</div>

I agree that gfortran has the right answer here. Please report the bug to Intel (in their forum if you don’t have paid support, or at their online service center if you do.
