External BLAS + gfortran does not build under the project's own -std=f2018
Summary
Building with an external BLAS/LAPACK and gfortran fails under stdlib's own -std=f2018 flag. On macOS this is the default path: CMake finds Accelerate on its own, so cmake -B build && cmake --build build does not complete.
-- Found external BLAS: .../Accelerate.framework
-- Found external LAPACK: .../Accelerate.framework;-lm;-ldl
...
[ 14%] Building Fortran object src/blas/.../stdlib_linalg_blas.F90.o
Error: GNU Extension: Symbol 'lda' is used before it is typed
Roughly 500 errors, all of that one kind, all inside the STDLIB_EXTERNAL_BLAS interface blocks.
Cause
The generated interface bodies declare an array before the bound it uses:
pure subroutine cgbmv(trans,m,n,kl,ku,alpha,a,lda,x,incx,beta,y,incy)
import sp,dp,qp,ilp,lk
implicit none
complex(sp), intent(in) :: alpha,beta,a(lda,*),x(*) ! lda used here
integer(ilp), intent(in) :: incx,incy,kl,ku,lda,m,n ! lda typed here
gfortran treats the forward reference as a GNU extension, so it is accepted under -std=gnu and rejected under -std=f2018. That exact interface, on its own:
| gfortran 15.2 | gfortran 16.2 | |
|---|---|---|
-std=gnu |
0 errors | 0 errors |
-std=f2018 |
errors | errors |
Twelve-line reproducer, the two orderings side by side:
interface
pure subroutine bad(a, lda) ! as generated
implicit none
real, intent(in) :: a(lda,*)
integer, intent(in) :: lda
end subroutine bad
end interface
interface
pure subroutine good(a, lda) ! bound first
implicit none
integer, intent(in) :: lda
real, intent(in) :: a(lda,*)
end subroutine good
end interface
gfortran -std=f2018 gives 4 errors for the first and 0 for the second. This is not new in gfortran 16 — 15.2 rejects it too.
Why CI does not see it
CI_BLAS is the only workflow that builds the external path, and its toolchain matrix is a single entry:
toolchain:
- { compiler: intel, version: "2024.1" }
So the STDLIB_EXTERNAL_BLAS interfaces are only ever compiled by ifx, which accepts the ordering. The gfortran jobs in CI build the bundled implementation instead and never reach these blocks.
Scope
The ordering appears on 106 declaration lines in src/blas/stdlib_linalg_blas.fypp and 1659 in src/lapack/stdlib_linalg_lapack.fypp, across 139 and 1480 interface bodies. Given the size, and that these read as machine-generated, this is not something to reorder by hand from the outside without knowing how they are produced.
Options, in the maintainers' hands:
- Emit the integer declaration before the arrays in whatever produces these interfaces.
- Add a gfortran entry to the
CI_BLASmatrix so the path is covered either way. - Treat the forward reference as legal and take it up with gfortran, if you read the standard as permitting it.
Happy to do (1) or (2) if you can point me at the generator, or say which you would prefer.
Found while working on #1209, which fixes the four -std=f2018 failures in the bundled build; this is the external-BLAS path and separate from it.
\cc @perazz