[flang-commits] [PATCH] D157330: [flang] Don't emit debugging output to module file

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc465158e45a6: [flang] Don't emit debugging output to module file (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157330/new/

https://reviews.llvm.org/D157330

Files:
  flang/lib/Evaluate/formatting.cpp
  flang/test/Semantics/modfile56.f90


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
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 <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 @@
 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(";
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157330.548276.patch
Type: text/x-patch
Size: 2000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230808/fb303c64/attachment-0001.bin>


More information about the flang-commits mailing list