[flang-commits] [flang] c465158 - [flang] Don't emit debugging output to module file

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Aug 8 10:28:21 PDT 2023


Author: Peter Klausler
Date: 2023-08-08T10:28:00-07:00
New Revision: c465158e45a66a391c279cbaabdff18ba627484a

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

LOG: [flang] Don't emit debugging output to module file

When a constant array value has a non-default lower bound, the current
expression formatting code uses a non-Fortran syntax to dump the lower
bounds. (There's no way in Fortran to explicitly specify such a constant value,
but they can be created through the use of named constants.)  But we
don't want this lower bounds syntax from expression dumping to show up
in module files, since it can't be parsed back in.  So disable that
part of expression formatting by default.

Fixes https://github.com/llvm/llvm-project/issues/64391.

Differential Revision: https://reviews.llvm.org/D157330

Added: 
    flang/test/Semantics/modfile56.f90

Modified: 
    flang/lib/Evaluate/formatting.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/formatting.cpp b/flang/lib/Evaluate/formatting.cpp
index 098cd7c9d8119b..52964fff76d6fa 100644
--- a/flang/lib/Evaluate/formatting.cpp
+++ b/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 @@ static void ShapeAsFortran(llvm::raw_ostream &o,
 template <typename RESULT, typename VALUE>
 llvm::raw_ostream &ConstantBase<RESULT, VALUE>::AsFortran(
     llvm::raw_ostream &o) const {
-  bool hasNonDefaultLowerBound{HasNonDefaultLowerBound()};
+  bool hasNonDefaultLowerBound{printLbounds && HasNonDefaultLowerBound()};
   if (Rank() > 1 || hasNonDefaultLowerBound) {
     o << "reshape(";
   }
@@ -90,7 +98,7 @@ llvm::raw_ostream &ConstantBase<RESULT, VALUE>::AsFortran(
 template <int KIND>
 llvm::raw_ostream &Constant<Type<TypeCategory::Character, KIND>>::AsFortran(
     llvm::raw_ostream &o) const {
-  bool hasNonDefaultLowerBound{HasNonDefaultLowerBound()};
+  bool hasNonDefaultLowerBound{printLbounds && HasNonDefaultLowerBound()};
   if (Rank() > 1 || hasNonDefaultLowerBound) {
     o << "reshape(";
   }

diff  --git a/flang/test/Semantics/modfile56.f90 b/flang/test/Semantics/modfile56.f90
new file mode 100644
index 00000000000000..9f15e64f9a6e99
--- /dev/null
+++ b/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


        


More information about the flang-commits mailing list