Index: flang/lib/Evaluate/formatting.cpp =================================================================== --- flang/lib/Evaluate/formatting.cpp +++ flang/lib/Evaluate/formatting.cpp @@ -19,6 +19,14 @@ namespace Fortran::evaluate { +// Constant arrays can have non-default lower bounds, but this can't be +// expressed in Fortran syntax directly, only implied through the use of +// named constant (PARAMETER) definitions. For debugging, setting this flag +// enables a non-standard %LBOUND=[...] argument to the RESHAPE intrinsic +// calls used to dumy constants. It's off by default so that this syntax +// doesn't show up in module files. +static const bool printLbounds{false}; + static void ShapeAsFortran(llvm::raw_ostream &o, const ConstantSubscripts &shape, const ConstantSubscripts &lbounds, bool hasNonDefaultLowerBound) { @@ -46,7 +54,7 @@ template llvm::raw_ostream &ConstantBase::AsFortran( llvm::raw_ostream &o) const { - bool hasNonDefaultLowerBound{HasNonDefaultLowerBound()}; + bool hasNonDefaultLowerBound{printLbounds && HasNonDefaultLowerBound()}; if (Rank() > 1 || hasNonDefaultLowerBound) { o << "reshape("; } @@ -90,7 +98,7 @@ template llvm::raw_ostream &Constant>::AsFortran( llvm::raw_ostream &o) const { - bool hasNonDefaultLowerBound{HasNonDefaultLowerBound()}; + bool hasNonDefaultLowerBound{printLbounds && HasNonDefaultLowerBound()}; if (Rank() > 1 || hasNonDefaultLowerBound) { o << "reshape("; } Index: flang/test/Semantics/modfile56.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/modfile56.f90 @@ -0,0 +1,10 @@ +! RUN: %python %S/test_modfile.py %s %flang_fc1 +! Named constant array with non-default lower bound +module m + real, parameter :: x(0:0) = [0.] +end + +!Expect: m.mod +!module m +!real(4),parameter::x(0_8:0_8)=[REAL(4)::0._4] +!end