[clang] 3338ef9 - [flang] Produce proper "preprocessor output" for -E option

peter klausler via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 30 15:14:06 PDT 2021


Author: peter klausler
Date: 2021-07-30T15:13:56-07:00
New Revision: 3338ef93b02837edf69abc203e15a42fa55aa1b3

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

LOG: [flang] Produce proper "preprocessor output" for -E option

Rename the current -E option to "-E -Xflang -fno-reformat".

Add a new Parsing::EmitPreprocessedSource() routine to convert the
cooked character stream output of the prescanner back to something
more closely resembling output from a traditional preprocessor;
call this new routine when -E appears.

The new -E output is suitable for use as fixed form Fortran source to
compilation by (one hopes) any Fortran compiler.  If the original
top-level source file had been free form source, the output will be
suitable for use as free form source as well; otherwise there may be
diagnostics about missing spaces if they were indeed absent in the
original fixed form source.

Unless the -P option appears, #line directives are interspersed
with the output (but be advised, f18 will ignore these if presented
with them in a later compilation).

An effort has been made to preserve original alphabetic character case
and source indentation.

Add -P and -fno-reformat to the new drivers.

Tweak test options to avoid confusion with prior -E output; use
-fno-reformat where needed, but prefer to keep -E, sometimes
in concert with -P, on most, updating expected results accordingly.

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

Added: 
    flang/test/Preprocessing/dash-E.F90

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Flang.cpp
    flang/include/flang/Frontend/FrontendOptions.h
    flang/include/flang/Frontend/PreprocessorOptions.h
    flang/include/flang/Parser/parsing.h
    flang/lib/Frontend/CompilerInvocation.cpp
    flang/lib/Frontend/FrontendActions.cpp
    flang/lib/Frontend/FrontendOptions.cpp
    flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
    flang/lib/Parser/parsing.cpp
    flang/lib/Parser/provenance.cpp
    flang/lib/Parser/token-sequence.cpp
    flang/lib/Parser/token-sequence.h
    flang/test/Driver/cpp-nocpp-command-line-macro.f90
    flang/test/Driver/driver-help-hidden.f90
    flang/test/Driver/driver-help.f90
    flang/test/Driver/escaped-backslash.f90
    flang/test/Driver/fixed-free-detection.f90
    flang/test/Driver/fixed-line-length.f90
    flang/test/Driver/frontend-forwarding.f90
    flang/test/Driver/include-header.f90
    flang/test/Driver/input-from-stdin.f90
    flang/test/Driver/macro-def-undef.F90
    flang/test/Driver/macro-multiline.F90
    flang/test/Parser/badlabel.f
    flang/test/Preprocessing/assert.F90
    flang/test/Preprocessing/fixed-rescan.F
    flang/test/Preprocessing/hollerith.f
    flang/test/Preprocessing/pp001.F
    flang/test/Preprocessing/pp002.F
    flang/test/Preprocessing/pp003.F
    flang/test/Preprocessing/pp004.F
    flang/test/Preprocessing/pp005.F
    flang/test/Preprocessing/pp006.F
    flang/test/Preprocessing/pp007.F
    flang/test/Preprocessing/pp008.F
    flang/test/Preprocessing/pp009.F
    flang/test/Preprocessing/pp010.F
    flang/test/Preprocessing/pp011.F
    flang/test/Preprocessing/pp012.F
    flang/test/Preprocessing/pp013.F
    flang/test/Preprocessing/pp014.F
    flang/test/Preprocessing/pp015.F
    flang/test/Preprocessing/pp016.F
    flang/test/Preprocessing/pp017.F
    flang/test/Preprocessing/pp018.F
    flang/test/Preprocessing/pp019.F
    flang/test/Preprocessing/pp020.F
    flang/test/Preprocessing/pp021.F
    flang/test/Preprocessing/pp022.F
    flang/test/Preprocessing/pp023.F
    flang/test/Preprocessing/pp024.F
    flang/test/Preprocessing/pp025.F
    flang/test/Preprocessing/pp026.F
    flang/test/Preprocessing/pp027.F
    flang/test/Preprocessing/pp028.F
    flang/test/Preprocessing/pp029.F
    flang/test/Preprocessing/pp030.F
    flang/test/Preprocessing/pp031.F
    flang/test/Preprocessing/pp032.F
    flang/test/Preprocessing/pp033.F
    flang/test/Preprocessing/pp034.F
    flang/test/Preprocessing/pp035.F
    flang/test/Preprocessing/pp036.F
    flang/test/Preprocessing/pp037.F
    flang/test/Preprocessing/pp038.F
    flang/test/Preprocessing/pp039.F
    flang/test/Preprocessing/pp041.F
    flang/test/Preprocessing/pp043.F
    flang/test/Preprocessing/pp044.F
    flang/test/Preprocessing/pp101.F90
    flang/test/Preprocessing/pp102.F90
    flang/test/Preprocessing/pp104.F90
    flang/test/Preprocessing/pp107.F90
    flang/test/Preprocessing/pp108.F90
    flang/test/Preprocessing/pp111.F90
    flang/test/Preprocessing/pp112.F90
    flang/test/Preprocessing/pp115.F90
    flang/test/Preprocessing/pp116.F90
    flang/test/Preprocessing/pp117.F90
    flang/test/Preprocessing/pp118.F90
    flang/test/Preprocessing/pp121.F90
    flang/test/Preprocessing/pp123.F90
    flang/test/Preprocessing/pp124.F90
    flang/test/Preprocessing/pp125.F90
    flang/test/Preprocessing/pp126.F90
    flang/test/Preprocessing/pp127.F90
    flang/test/Preprocessing/pp128.F90
    flang/tools/f18-parse-demo/f18-parse-demo.cpp
    flang/tools/f18/f18.cpp
    flang/unittests/Frontend/FrontendActionTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 64d612d7dbd1..34442060e277 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -701,7 +701,7 @@ def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>,
 def O : Joined<["-"], "O">, Group<O_Group>, Flags<[CC1Option]>;
 def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias<O>, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group<O_Group>, Flags<[CC1Option]>;
-def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group<Preprocessor_Group>,
+def P : Flag<["-"], "P">, Flags<[CC1Option,FlangOption,FC1Option]>, Group<Preprocessor_Group>,
   HelpText<"Disable linemarker output in -E mode">,
   MarshallingInfoNegativeFlag<PreprocessorOutputOpts<"ShowLineMarkers">>;
 def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>,
@@ -4570,7 +4570,7 @@ def fdebug_measure_parse_tree : Flag<["-"], "fdebug-measure-parse-tree">, Group<
   HelpText<"Measure the parse tree">;
 def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, Group<Action_Group>,
   HelpText<"Dump the pre-FIR tree">;
-def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">, 
+def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">,
   HelpText<"Enable debug messages while writing module files">;
 def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Group>,
   HelpText<"Dump symbols and their source code locations">;
@@ -4582,7 +4582,8 @@ def fanalyzed_objects_for_unparse : Flag<["-"],
 def fno_analyzed_objects_for_unparse : Flag<["-"],
   "fno-analyzed-objects-for-unparse">,  Group<f_Group>,
   HelpText<"Do not use the analyzed objects when unparsing">;
-
+def fno_reformat : Flag<["-"], "fno-reformat">, Group<Preprocessor_Group>,
+  HelpText<"Dump the cooked character stream in -E mode">;
 }
 
 //===----------------------------------------------------------------------===//

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 1bfad6115d51..b82c5d7600df 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -37,8 +37,9 @@ void Flang::AddFortranDialectOptions(const ArgList &Args,
 
 void Flang::AddPreprocessingOptions(const ArgList &Args,
                                     ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I,
-                            options::OPT_cpp, options::OPT_nocpp});
+  Args.AddAllArgs(CmdArgs,
+                  {options::OPT_P, options::OPT_D, options::OPT_U,
+                   options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
 }
 
 void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 42ce499566e9..a40e37125ded 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -25,7 +25,7 @@ enum ActionKind {
   /// -test-io mode
   InputOutputTest,
 
-  /// -E mode.
+  /// -E mode
   PrintPreprocessedInput,
 
   /// -fsyntax-only

diff  --git a/flang/include/flang/Frontend/PreprocessorOptions.h b/flang/include/flang/Frontend/PreprocessorOptions.h
index 1e833194ac35..0973a9a6357f 100644
--- a/flang/include/flang/Frontend/PreprocessorOptions.h
+++ b/flang/include/flang/Frontend/PreprocessorOptions.h
@@ -44,6 +44,12 @@ class PreprocessorOptions {
 
   PPMacrosFlag macrosFlag_ = PPMacrosFlag::Unknown;
 
+  // -P: Suppress #line directives in -E output
+  bool noLineDirectives{false};
+
+  // -fno-reformat: Emit cooked character stream as -E output
+  bool noReformat{false};
+
 public:
   PreprocessorOptions() {}
 

diff  --git a/flang/include/flang/Parser/parsing.h b/flang/include/flang/Parser/parsing.h
index d41d9a580740..be2527981494 100644
--- a/flang/include/flang/Parser/parsing.h
+++ b/flang/include/flang/Parser/parsing.h
@@ -37,6 +37,7 @@ struct Options {
   bool isModuleFile{false};
   bool needProvenanceRangeToCharBlockMappings{false};
   Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
+  bool prescanAndReformat{false}; // -E
 };
 
 class Parsing {
@@ -47,12 +48,15 @@ class Parsing {
   bool consumedWholeFile() const { return consumedWholeFile_; }
   const char *finalRestingPlace() const { return finalRestingPlace_; }
   AllCookedSources &allCooked() { return allCooked_; }
+  const AllCookedSources &allCooked() const { return allCooked_; }
   Messages &messages() { return messages_; }
   std::optional<Program> &parseTree() { return parseTree_; }
 
   const CookedSource &cooked() const { return DEREF(currentCooked_); }
 
   const SourceFile *Prescan(const std::string &path, Options);
+  void EmitPreprocessedSource(
+      llvm::raw_ostream &, bool lineDirectives = true) const;
   void DumpCookedChars(llvm::raw_ostream &) const;
   void DumpProvenance(llvm::raw_ostream &) const;
   void DumpParsingLog(llvm::raw_ostream &) const;

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 6a2bf1947e35..bd79b0170e63 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -371,6 +371,9 @@ static void parsePreprocessorArgs(
         (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
         ? PPMacrosFlag::Include
         : PPMacrosFlag::Exclude;
+
+  opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
+  opts.noLineDirectives = args.hasArg(clang::driver::options::OPT_P);
 }
 
 /// Parses all semantic related arguments and populates the variables

diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index fae058468275..9ec751bec2be 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -208,9 +208,14 @@ void PrintPreprocessedAction::ExecuteAction() {
   std::string buf;
   llvm::raw_string_ostream outForPP{buf};
 
-  // Run the preprocessor
+  // Format or dump the prescanner's output
   CompilerInstance &ci = this->instance();
-  ci.parsing().DumpCookedChars(outForPP);
+  if (ci.invocation().preprocessorOpts().noReformat) {
+    ci.parsing().DumpCookedChars(outForPP);
+  } else {
+    ci.parsing().EmitPreprocessedSource(
+        outForPP, !ci.invocation().preprocessorOpts().noLineDirectives);
+  }
 
   // If a pre-defined output stream exists, dump the preprocessed content there
   if (!ci.IsOutputStreamNull()) {
@@ -219,7 +224,7 @@ void PrintPreprocessedAction::ExecuteAction() {
     return;
   }
 
-  // Print diagnostics from the preprocessor
+  // Print diagnostics from the prescanner
   ci.parsing().messages().Emit(llvm::errs(), ci.allCookedSources());
 
   // Create a file and save the preprocessed output there
@@ -228,7 +233,6 @@ void PrintPreprocessedAction::ExecuteAction() {
     (*os) << outForPP.str();
   } else {
     llvm::errs() << "Unable to create the output file\n";
-    return;
   }
 }
 

diff  --git a/flang/lib/Frontend/FrontendOptions.cpp b/flang/lib/Frontend/FrontendOptions.cpp
index dcad975284ad..886baa39ee57 100644
--- a/flang/lib/Frontend/FrontendOptions.cpp
+++ b/flang/lib/Frontend/FrontendOptions.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Frontend/FrontendOptions.h"
-#include "flang/Evaluate/expression.h"
 
 using namespace Fortran::frontend;
 

diff  --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 243e25163dc0..9c3b13b6070d 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -28,61 +28,43 @@ static std::unique_ptr<FrontendAction> CreateFrontendBaseAction(
   switch (ak) {
   case InputOutputTest:
     return std::make_unique<InputOutputTestAction>();
-    break;
   case PrintPreprocessedInput:
     return std::make_unique<PrintPreprocessedAction>();
-    break;
   case ParseSyntaxOnly:
     return std::make_unique<ParseSyntaxOnlyAction>();
   case EmitObj:
     return std::make_unique<EmitObjAction>();
-    break;
   case DebugUnparse:
     return std::make_unique<DebugUnparseAction>();
-    break;
   case DebugUnparseNoSema:
     return std::make_unique<DebugUnparseNoSemaAction>();
-    break;
   case DebugUnparseWithSymbols:
     return std::make_unique<DebugUnparseWithSymbolsAction>();
-    break;
   case DebugDumpSymbols:
     return std::make_unique<DebugDumpSymbolsAction>();
-    break;
   case DebugDumpParseTree:
     return std::make_unique<DebugDumpParseTreeAction>();
-    break;
   case DebugDumpParseTreeNoSema:
     return std::make_unique<DebugDumpParseTreeNoSemaAction>();
-    break;
   case DebugDumpAll:
     return std::make_unique<DebugDumpAllAction>();
-    break;
   case DebugDumpProvenance:
     return std::make_unique<DebugDumpProvenanceAction>();
-    break;
   case DebugDumpParsingLog:
     return std::make_unique<DebugDumpParsingLogAction>();
-    break;
   case DebugMeasureParseTree:
     return std::make_unique<DebugMeasureParseTreeAction>();
-    break;
   case DebugPreFIRTree:
     return std::make_unique<DebugPreFIRTreeAction>();
-    break;
   case GetDefinition:
     return std::make_unique<GetDefinitionAction>();
-    break;
   case GetSymbolsSources:
     return std::make_unique<GetSymbolsSourcesAction>();
-    break;
   case InitOnly:
     return std::make_unique<InitOnlyAction>();
-    break;
   default:
     break;
     // TODO:
-    // case RunPreprocessor:
     // case ParserSyntaxOnly:
     // case EmitLLVM:
     // case EmitLLVMOnly:

diff  --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index 0afa2a94ac40..92736619ec36 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -95,6 +95,94 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
   return sourceFile;
 }
 
+void Parsing::EmitPreprocessedSource(
+    llvm::raw_ostream &out, bool lineDirectives) const {
+  const SourceFile *sourceFile{nullptr};
+  int sourceLine{0};
+  int column{1};
+  bool inDirective{false};
+  bool inContinuation{false};
+  const AllSources &allSources{allCooked().allSources()};
+  for (const char &atChar : cooked().AsCharBlock()) {
+    char ch{atChar};
+    if (ch == '\n') {
+      out << '\n'; // TODO: DOS CR-LF line ending if necessary
+      column = 1;
+      inDirective = false;
+      inContinuation = false;
+      ++sourceLine;
+    } else {
+      if (ch == '!') {
+        // Other comment markers (C, *, D) in original fixed form source
+        // input card column 1 will have been deleted or normalized to !,
+        // which signifies a comment (directive) in both source forms.
+        inDirective = true;
+      }
+      auto provenance{cooked().GetProvenanceRange(CharBlock{&atChar, 1})};
+      std::optional<SourcePosition> position{provenance
+              ? allSources.GetSourcePosition(provenance->start())
+              : std::nullopt};
+      if (lineDirectives && column == 1 && position) {
+        if (&position->file != sourceFile) {
+          out << "#line \"" << position->file.path() << "\" " << position->line
+              << '\n';
+        } else if (position->line != sourceLine) {
+          if (sourceLine < position->line &&
+              sourceLine + 10 >= position->line) {
+            // Emit a few newlines to catch up when they'll likely
+            // require fewer bytes than a #line directive would have
+            // occupied.
+            while (sourceLine++ < position->line) {
+              out << '\n';
+            }
+          } else {
+            out << "#line " << position->line << '\n';
+          }
+        }
+        sourceFile = &position->file;
+        sourceLine = position->line;
+      }
+      if (column > 72) {
+        // Wrap long lines in a portable fashion that works in both
+        // of the Fortran source forms.  The first free-form continuation
+        // marker ("&") lands in column 73, which begins the card commentary
+        // field of fixed form, and the second one is put in column 6,
+        // where it signifies fixed form line continuation.
+        // The standard Fortran fixed form column limit (72) is used
+        // for output, even if the input was parsed with a nonstandard
+        // column limit override option.
+        out << "&\n     &";
+        column = 7; // start of fixed form source field
+        ++sourceLine;
+        inContinuation = true;
+      } else if (!inDirective && ch != ' ' && (ch < '0' || ch > '9')) {
+        // Put anything other than a label or directive into the
+        // Fortran fixed form source field (columns [7:72]).
+        for (; column < 7; ++column) {
+          out << ' ';
+        }
+      }
+      if (!inContinuation && position && position->column <= 72 && ch != ' ') {
+        // Preserve original indentation
+        for (; column < position->column; ++column) {
+          out << ' ';
+        }
+      }
+      if (ch >= 'a' && ch <= 'z' && provenance && provenance->size() == 1) {
+        // Preserve original case
+        if (const char *orig{allSources.GetSource(*provenance)}) {
+          auto upper{static_cast<char>(ch + 'A' - 'a')};
+          if (*orig == upper) {
+            ch = upper;
+          }
+        }
+      }
+      out << ch;
+      ++column;
+    }
+  }
+}
+
 void Parsing::DumpCookedChars(llvm::raw_ostream &out) const {
   UserState userState{allCooked_, common::LanguageFeatureControl{}};
   ParseState parseState{cooked()};

diff  --git a/flang/lib/Parser/provenance.cpp b/flang/lib/Parser/provenance.cpp
index 86de7657f961..cb8fbe7a4cda 100644
--- a/flang/lib/Parser/provenance.cpp
+++ b/flang/lib/Parser/provenance.cpp
@@ -323,12 +323,20 @@ const char *AllSources::GetSource(ProvenanceRange range) const {
 std::optional<SourcePosition> AllSources::GetSourcePosition(
     Provenance prov) const {
   const Origin &origin{MapToOrigin(prov)};
-  if (const auto *inc{std::get_if<Inclusion>(&origin.u)}) {
-    std::size_t offset{origin.covers.MemberOffset(prov)};
-    return inc->source.FindOffsetLineAndColumn(offset);
-  } else {
-    return std::nullopt;
-  }
+  return std::visit(
+      common::visitors{
+          [&](const Inclusion &inc) -> std::optional<SourcePosition> {
+            std::size_t offset{origin.covers.MemberOffset(prov)};
+            return inc.source.FindOffsetLineAndColumn(offset);
+          },
+          [&](const Macro &) {
+            return GetSourcePosition(origin.replaces.start());
+          },
+          [](const CompilerInsertion &) -> std::optional<SourcePosition> {
+            return std::nullopt;
+          },
+      },
+      origin.u);
 }
 
 std::optional<ProvenanceRange> AllSources::GetFirstFileProvenance() const {
@@ -593,7 +601,7 @@ std::optional<CharBlock> AllCookedSources::GetCharBlock(
       return result;
     }
   }
-  return nullptr;
+  return std::nullopt;
 }
 
 void AllCookedSources::Dump(llvm::raw_ostream &o) const {

diff  --git a/flang/lib/Parser/token-sequence.cpp b/flang/lib/Parser/token-sequence.cpp
index cdf066dcf777..0a959f28336f 100644
--- a/flang/lib/Parser/token-sequence.cpp
+++ b/flang/lib/Parser/token-sequence.cpp
@@ -276,13 +276,14 @@ void TokenSequence::Emit(CookedSource &cooked) const {
   cooked.PutProvenanceMappings(provenances_);
 }
 
-void TokenSequence::Dump(llvm::raw_ostream &o) const {
+llvm::raw_ostream &TokenSequence::Dump(llvm::raw_ostream &o) const {
   o << "TokenSequence has " << char_.size() << " chars; nextStart_ "
     << nextStart_ << '\n';
   for (std::size_t j{0}; j < start_.size(); ++j) {
     o << '[' << j << "] @ " << start_[j] << " '" << TokenAt(j).ToString()
       << "'\n";
   }
+  return o;
 }
 
 Provenance TokenSequence::GetTokenProvenance(

diff  --git a/flang/lib/Parser/token-sequence.h b/flang/lib/Parser/token-sequence.h
index 6a10ef1977d3..16cef37e44f7 100644
--- a/flang/lib/Parser/token-sequence.h
+++ b/flang/lib/Parser/token-sequence.h
@@ -119,7 +119,7 @@ class TokenSequence {
   TokenSequence &ClipComment(bool skipFirst = false);
   const TokenSequence &CheckBadFortranCharacters(Messages &) const;
   void Emit(CookedSource &) const;
-  void Dump(llvm::raw_ostream &) const;
+  llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
 
 private:
   std::size_t TokenBytes(std::size_t token) const {

diff  --git a/flang/test/Driver/cpp-nocpp-command-line-macro.f90 b/flang/test/Driver/cpp-nocpp-command-line-macro.f90
index 1aacde0f308f..3c0aeeeee239 100644
--- a/flang/test/Driver/cpp-nocpp-command-line-macro.f90
+++ b/flang/test/Driver/cpp-nocpp-command-line-macro.f90
@@ -8,11 +8,11 @@
 !-----------------
 ! EXPECTED OUTPUT
 !-----------------
-! UNDEFINED:program b
-! UNDEFINED-NOT:program a
+! UNDEFINED:program B
+! UNDEFINED-NOT:program A
 
-! DEFINED:program a
-! DEFINED-NOT:program b
+! DEFINED:program A
+! DEFINED-NOT:program B
 
 #ifdef X
 program X

diff  --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 5bbdbb8ab749..c9e341045a02 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -50,6 +50,7 @@
 ! CHECK-NEXT: -nocpp                 Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o <file> Write output to <file>
 ! CHECK-NEXT: -pedantic              Warn on language extensions
+! CHECK-NEXT: -P                     Disable linemarker output in -E mode
 ! CHECK-NEXT: -std=<value>           Language standard to compile for
 ! CHECK-NEXT: -U <macro>             Undefine macro <macro>
 ! CHECK-NEXT: --version Print version information

diff  --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index db672364a2b6..415e2d004c00 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -50,6 +50,7 @@
 ! HELP-NEXT: -nocpp                 Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o <file>              Write output to <file>
 ! HELP-NEXT: -pedantic              Warn on language extensions
+! HELP-NEXT: -P                     Disable linemarker output in -E mode
 ! HELP-NEXT: -std=<value>           Language standard to compile for
 ! HELP-NEXT: -U <macro>             Undefine macro <macro>
 ! HELP-NEXT: --version              Print version information
@@ -103,6 +104,7 @@
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fno-analyzed-objects-for-unparse
 ! HELP-FC1-NEXT:                        Do not use the analyzed objects when unparsing
+! HELP-FC1-NEXT: -fno-reformat          Dump the cooked character stream in -E mode
 ! HELP-FC1-NEXT: -fopenacc              Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp               Parse OpenMP pragmas and generate parallel code.
 ! HELP-FC1-NEXT: -fxor-operator         Enable .XOR. as a synonym of .NEQV.
@@ -114,6 +116,7 @@
 ! HELP-FC1-NEXT: -nocpp                 Disable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -o <file>              Write output to <file>
 ! HELP-FC1-NEXT: -pedantic              Warn on language extensions
+! HELP-FC1-NEXT: -P                     Disable linemarker output in -E mode
 ! HELP-FC1-NEXT: -std=<value>           Language standard to compile for
 ! HELP-FC1-NEXT: -test-io               Run the InputOuputTest action. Use for development and testing only.
 ! HELP-FC1-NEXT: -U <macro>             Undefine macro <macro>

diff  --git a/flang/test/Driver/escaped-backslash.f90 b/flang/test/Driver/escaped-backslash.f90
index 20e48c6de004..16cf2654e2aa 100644
--- a/flang/test/Driver/escaped-backslash.f90
+++ b/flang/test/Driver/escaped-backslash.f90
@@ -17,14 +17,14 @@
 !-----------------------------------------
 ! EXPECTED OUTPUT FOR ESCAPED BACKSLASHES
 !-----------------------------------------
-! ESCAPED:program backslash
+! ESCAPED:program Backslash
 ! ESCAPED-NEXT:New\\nline
 ! ESCAPED-NOT:New\nline
 
 !-------------------------------------------
 ! EXPECTED OUTPUT FOR UNESCAPED BACKSLASHES
 !-------------------------------------------
-! UNESCAPED:program backslash
+! UNESCAPED:program Backslash
 ! UNESCAPED-NEXT:New\nline
 ! UNESCAPED-NOT:New\\nline
 

diff  --git a/flang/test/Driver/fixed-free-detection.f90 b/flang/test/Driver/fixed-free-detection.f90
index abbe17d2a663..bdca422a04b6 100644
--- a/flang/test/Driver/fixed-free-detection.f90
+++ b/flang/test/Driver/fixed-free-detection.f90
@@ -1,20 +1,20 @@
 ! Ensure the driver correctly switches between fixed and free form based on the file extension.
-! This test exploits the fact that the preprocessor treats white-spaces 
diff erently for free
+! This test exploits the fact that the prescanner treats whitespace 
diff erently for free
 ! and fixed form input files.
 
 !--------------------------
 ! FLANG DRIVER (flang)
 !--------------------------
-! RUN: %flang -E %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
-! RUN: %flang -E %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
-! RUN: %flang -E %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
+! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
 
 !-----------------------------------------
 ! FRONTEND FLANG DRIVER (flang_fc1)
 !-----------------------------------------
-! RUN: %flang_fc1 -E %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
-! RUN: %flang_fc1 -E %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
-! RUN: %flang_fc1 -E %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
+! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
 
 !-------------------------------------
 ! EXPECTED OUTPUT FOR A FREE FORM FILE

diff  --git a/flang/test/Driver/fixed-line-length.f90 b/flang/test/Driver/fixed-line-length.f90
index 5db2828f4555..930b20b956b0 100644
--- a/flang/test/Driver/fixed-line-length.f90
+++ b/flang/test/Driver/fixed-line-length.f90
@@ -5,28 +5,28 @@
 !--------------------------
 ! FLANG DRIVER (flang)
 !--------------------------
-! RUN: %flang -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
-! RUN: not %flang -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
-! RUN: not %flang -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
-! RUN: %flang -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
-! RUN: %flang -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
-! RUN: %flang -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang -E -Xflang -fno-reformat %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang -E -Xflang -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
 
 !----------------------------------------
 ! FRONTEND FLANG DRIVER (flang -fc1)
 !----------------------------------------
-! RUN: %flang_fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
-! RUN: not %flang_fc1 -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
-! RUN: not %flang_fc1 -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
-! RUN: %flang_fc1 -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
-! RUN: %flang_fc1 -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
-! RUN: %flang_fc1 -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang_fc1 -E -fno-reformat %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang_fc1 -E -fno-reformat -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
 
 !-------------------------------------
 ! COMMAND ALIAS -ffixed-line-length-n
 !-------------------------------------
-! RUN: %flang -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
-! RUN: %flang_fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang -E -Xflang -fno-reformat -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang_fc1 -E -fno-reformat -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
 
 !-------------------------------------
 ! EXPECTED OUTPUT WITH DEFAULT LENGTH

diff  --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index 7d24b97aae89..d206ff04e1ae 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -9,8 +9,10 @@
 ! RUN:     -fdefault-integer-8 \
 ! RUN:     -fdefault-real-8 \
 ! RUN:     -flarge-sizes \
+! RUN:     -P \
 ! RUN:   | FileCheck %s
 
+! CHECK: "-P"
 ! CHECK: "-finput-charset=utf-8"
 ! CHECK: "-fdefault-double-8"
 ! CHECK: "-fdefault-integer-8"

diff  --git a/flang/test/Driver/include-header.f90 b/flang/test/Driver/include-header.f90
index 6dbcfc1def62..672f1b0ad740 100644
--- a/flang/test/Driver/include-header.f90
+++ b/flang/test/Driver/include-header.f90
@@ -26,35 +26,32 @@
 !---------------------------------------------
 ! EXPECTED OUTPUT FOR A SINGLE INCLUDED FOLDER
 !--------------------------------------------
-! SINGLEINCLUDE:program maindirectoryone
-! SINGLEINCLUDE-NOT:program x
-! SINGLEINCLUDE-NOT:program b
-! SINGLEINCLUDE-NEXT:end
-! SINGLEINCLUDE-NEXT:program maindirectorytwo
-! SINGLEINCLUDE-NOT:program y
-! SINGLEINCLUDE-NOT:program c
+! SINGLEINCLUDE:program MainDirectoryOne
+! SINGLEINCLUDE-NOT:program X
+! SINGLEINCLUDE-NOT:program B
+! SINGLEINCLUDE:program MainDirectoryTwo
+! SINGLEINCLUDE-NOT:program Y
+! SINGLEINCLUDE-NOT:program C
 
 !-------------------------------------------------------
 ! EXPECTED OUTPUT FOR Inputs/ DIRECTORY SPECIFIED FIRST
 !-------------------------------------------------------
-! MAINDIRECTORY:program maindirectoryone
-! MAINDIRECTORY-NOT:program subdirectoryone
-! MAINDIRECTORY-NOT:program b
-! MAINDIRECTORY-NEXT:end
-! MAINDIRECTORY-NEXT:program maindirectorytwo
-! MAINDIRECTORY-NOT:program subdirectorytwo
-! MAINDIRECTORY-NOT:program c
+! MAINDIRECTORY:program MainDirectoryOne
+! MAINDIRECTORY-NOT:program SubDirectoryOne
+! MAINDIRECTORY-NOT:program B
+! MAINDIRECTORY:program MainDirectoryTwo
+! MAINDIRECTORY-NOT:program SubDirectoryTwo
+! MAINDIRECTORY-NOT:program C
 
 !------------------------------------------------------------------
 ! EXPECTED OUTPUT FOR Inputs/header-dir/ DIRECTORY SPECIFIED FIRST
 !------------------------------------------------------------------
-! SUBDIRECTORY:program subdirectoryone
-! SUBDIRECTORY-NOT:program maindirectoryone
-! SUBDIRECTORY-NOT:program b
-! SUBDIRECTORY-NEXT:end
-! SUBDIRECTORY-NEXT:program subdirectorytwo
-! SUBDIRECTORY-NOT:program maindirectorytwo
-! SUBDIRECTORY-NOT:program c
+! SUBDIRECTORY:program SubDirectoryOne
+! SUBDIRECTORY-NOT:program MainDirectoryOne
+! SUBDIRECTORY-NOT:program B
+! SUBDIRECTORY:program SubDirectoryTwo
+! SUBDIRECTORY-NOT:program MainDirectoryTwo
+! SUBDIRECTORY-NOT:program C
 
 ! include-test-one.f90
 #include <basic-header-one.h>

diff  --git a/flang/test/Driver/input-from-stdin.f90 b/flang/test/Driver/input-from-stdin.f90
index 4f14e37a8360..4829024d7c0b 100644
--- a/flang/test/Driver/input-from-stdin.f90
+++ b/flang/test/Driver/input-from-stdin.f90
@@ -30,8 +30,8 @@
 !-------------------------
 ! EXPECTED OUTPUT for `-E`
 !-------------------------
-! PP-NOT-DEFINED: program b
-! PP-DEFINED: program a
+! PP-NOT-DEFINED: Program B
+! PP-DEFINED: Program A
 
 !-------------------------------
 ! EXPECTED OUTPUT for `-test-io`

diff  --git a/flang/test/Driver/macro-def-undef.F90 b/flang/test/Driver/macro-def-undef.F90
index b2310fae0dc1..59b79bc445d4 100644
--- a/flang/test/Driver/macro-def-undef.F90
+++ b/flang/test/Driver/macro-def-undef.F90
@@ -3,30 +3,28 @@
 !--------------------------
 ! FLANG DRIVER (flang-new)
 !--------------------------
-! RUN: %flang -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
-! RUN: %flang -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
-! RUN: %flang -E -DX=A -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang -E -P %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang -E -P -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang -E -P -DX=A -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
 
 !-----------------------------------------
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-----------------------------------------
-! RUN: %flang_fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
-! RUN: %flang_fc1 -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
-! RUN: %flang_fc1 -E -DX -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang_fc1 -E -P %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang_fc1 -E -P -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang_fc1 -E -P -DX -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
 
 !--------------------------------------------
 ! EXPECTED OUTPUT FOR AN UNDEFINED MACRO
 !--------------------------------------------
-! UNDEFINED:program b
-! UNDEFINED-NOT:program x
-! UNDEFINED-NEXT:end
+! UNDEFINED:program B
+! UNDEFINED-NOT:program X
 
 !--------------------------------------------
 ! EXPECTED OUTPUT FOR MACRO 'X' DEFINED AS A
 !--------------------------------------------
-! DEFINED:program a
-! DEFINED-NOT:program b
-! DEFINED-NEXT:end
+! DEFINED:program A
+! DEFINED-NOT:program B
 
 #ifdef X
 program X

diff  --git a/flang/test/Driver/macro-multiline.F90 b/flang/test/Driver/macro-multiline.F90
index 8023459940be..0bf23f0fe48f 100644
--- a/flang/test/Driver/macro-multiline.F90
+++ b/flang/test/Driver/macro-multiline.F90
@@ -5,18 +5,18 @@
 !--------------------------
 ! FLANG DRIVER (flang)
 !--------------------------
-! RUN: printf -- "-DX=A\\\\\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang -E %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
+! RUN: printf -- "-DX=A\\\\\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang -E -P %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
 
 !-----------------------------------------
 ! FRONTEND FLANG DRIVER (flang_fc1)
 !-----------------------------------------
-! RUN: printf -- "-DX=A\\\\\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang_fc1 -E %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
+! RUN: printf -- "-DX=A\\\\\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang_fc1 -E -P %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
 
 !-------------------------------
 ! EXPECTED OUTPUT FOR MACRO 'X'
 !-------------------------------
-! CHECK:start a end
+! CHECK:       START A END
 ! CHECK-NOT:THIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT
 ! CHECK-NOT:this_should_not_exist_in_the_output
 
-START X END
+       START X END

diff  --git a/flang/test/Parser/badlabel.f b/flang/test/Parser/badlabel.f
index 819dcf894298..ea36ec6faab5 100644
--- a/flang/test/Parser/badlabel.f
+++ b/flang/test/Parser/badlabel.f
@@ -1,4 +1,4 @@
-! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -E -fno-reformat %s 2>&1 | FileCheck %s
 ! CHECK: Label digit is not in fixed-form label field
       1 continue
 ! CHECK: Label digit is not in fixed-form label field

diff  --git a/flang/test/Preprocessing/assert.F90 b/flang/test/Preprocessing/assert.F90
index 5d4837efd6d5..e53b4de863ed 100644
--- a/flang/test/Preprocessing/assert.F90
+++ b/flang/test/Preprocessing/assert.F90
@@ -1,4 +1,4 @@
-!RUN: %flang -E %s 2>&1 | FileCheck %s
+!RUN: %flang -E -Xflang -fno-reformat %s 2>&1 | FileCheck %s
 !CHECK: if(.not.(.true.)) error stop "assert(" // ".TRUE." // ") failed " // "at ""
 !CHECK-SAME: assert.F90"": " // "7"
 #define STR(x) #x

diff  --git a/flang/test/Preprocessing/dash-E.F90 b/flang/test/Preprocessing/dash-E.F90
new file mode 100644
index 000000000000..9252ea27cafe
--- /dev/null
+++ b/flang/test/Preprocessing/dash-E.F90
@@ -0,0 +1,25 @@
+! RUN: %flang -E %s 2>&1 | FileCheck --strict-whitespace %s
+!CHECK:       program Main
+program Main
+#define ADD(x,y) (x)+(y)
+!CHECK:       integer :: j = (1)+( 2)
+  integer :: j = ADD(1,&
+                     2)
+!CHECK:1     format('This is a very long output literal edit descriptor for a F&
+!CHECK:     &ORMAT statement, and it will require statement continuation.')
+1 format('This is a very long output literal edit descriptor for a FORMAT statement, and it will require statement continuation.')
+
+
+
+
+
+
+
+
+
+
+
+
+!CHECK: #line 25
+!CHECK:       end PROGRAM Main
+end PROGRAM Main

diff  --git a/flang/test/Preprocessing/fixed-rescan.F b/flang/test/Preprocessing/fixed-rescan.F
index ac983e7c3194..f6e55e377baa 100644
--- a/flang/test/Preprocessing/fixed-rescan.F
+++ b/flang/test/Preprocessing/fixed-rescan.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s | FileCheck %s
-! CHECK: callbar
+! CHECK: call bar
 ! Ensure that rescanned lines after macro replacement are not
 ! misinterpreted as fixed-form comments when they start with C or D.
 #define foo bar

diff  --git a/flang/test/Preprocessing/hollerith.f b/flang/test/Preprocessing/hollerith.f
index 5f20259c57a8..a707d2bc484b 100644
--- a/flang/test/Preprocessing/hollerith.f
+++ b/flang/test/Preprocessing/hollerith.f
@@ -1,4 +1,4 @@
-! RUN: %flang -E %s 2>&1 | FileCheck %s
+! RUN: %flang -E -Xflang -fno-reformat %s 2>&1 | FileCheck %s
 ! CHECK: character*1hi
 ! CHECK: dataa/1*1h /
 ! CHECK: datab/1*1h /

diff  --git a/flang/test/Preprocessing/pp001.F b/flang/test/Preprocessing/pp001.F
index 455da7302763..e222b9598df1 100644
--- a/flang/test/Preprocessing/pp001.F
+++ b/flang/test/Preprocessing/pp001.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
+! CHECK: if (777 .eq. 777) then
 * keyword macros
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp002.F b/flang/test/Preprocessing/pp002.F
index d673fcdbd6da..4faa9eef96d9 100644
--- a/flang/test/Preprocessing/pp002.F
+++ b/flang/test/Preprocessing/pp002.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm.eq.777)then
+! CHECK: if (KWM .eq. 777) then
 * #undef
       integer, parameter :: KWM = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp003.F b/flang/test/Preprocessing/pp003.F
index 2062dbcee703..56df98309f43 100644
--- a/flang/test/Preprocessing/pp003.F
+++ b/flang/test/Preprocessing/pp003.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * function-like macros
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp004.F b/flang/test/Preprocessing/pp004.F
index f5724df45d52..3c4d111c4851 100644
--- a/flang/test/Preprocessing/pp004.F
+++ b/flang/test/Preprocessing/pp004.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm.eq.777)then
+! CHECK: if (kwm .eq. 777) then
 * KWMs case-sensitive
       integer, parameter :: KWM = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp005.F b/flang/test/Preprocessing/pp005.F
index 48cf12df628e..e4483b404c36 100644
--- a/flang/test/Preprocessing/pp005.F
+++ b/flang/test/Preprocessing/pp005.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=777
+! CHECK: res = 777
 * KWM split across continuation, implicit padding
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp006.F b/flang/test/Preprocessing/pp006.F
index f878bfddd143..f526ad31733e 100644
--- a/flang/test/Preprocessing/pp006.F
+++ b/flang/test/Preprocessing/pp006.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=777
+! CHECK: res = 777
 * ditto, but with intervening *comment line
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp007.F b/flang/test/Preprocessing/pp007.F
index a5d871a2d1c1..8c6a5b4c40bb 100644
--- a/flang/test/Preprocessing/pp007.F
+++ b/flang/test/Preprocessing/pp007.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=kwm
+! CHECK: res = KWM
 * KWM split across continuation, clipped after column 72
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp008.F b/flang/test/Preprocessing/pp008.F
index 7e580efddb65..08d809da3e51 100644
--- a/flang/test/Preprocessing/pp008.F
+++ b/flang/test/Preprocessing/pp008.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=kwm
+! CHECK: res = K W M
 * KWM with spaces in name at invocation NOT replaced
       integer, parameter :: KWM = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp009.F b/flang/test/Preprocessing/pp009.F
index b6a6249c0544..84c8c709ef52 100644
--- a/flang/test/Preprocessing/pp009.F
+++ b/flang/test/Preprocessing/pp009.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call split across continuation, implicit padding
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp010.F b/flang/test/Preprocessing/pp010.F
index e860bd9f3abe..d8bc5a79ec75 100644
--- a/flang/test/Preprocessing/pp010.F
+++ b/flang/test/Preprocessing/pp010.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * ditto, but with intervening *comment line
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp011.F b/flang/test/Preprocessing/pp011.F
index af0e0e88b333..08b531ad64a8 100644
--- a/flang/test/Preprocessing/pp011.F
+++ b/flang/test/Preprocessing/pp011.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=iflm(666)
+! CHECK: res = IFLM(666)
 * FLM call name split across continuation, clipped
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp012.F b/flang/test/Preprocessing/pp012.F
index 12ab61233275..de4da074f08d 100644
--- a/flang/test/Preprocessing/pp012.F
+++ b/flang/test/Preprocessing/pp012.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call name split across continuation
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp013.F b/flang/test/Preprocessing/pp013.F
index 07bb25e7c8d6..00e80fcb504e 100644
--- a/flang/test/Preprocessing/pp013.F
+++ b/flang/test/Preprocessing/pp013.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call split between name and (
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp014.F b/flang/test/Preprocessing/pp014.F
index 7ac5d382bc7d..66742a36a894 100644
--- a/flang/test/Preprocessing/pp014.F
+++ b/flang/test/Preprocessing/pp014.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call split between name and (, with intervening *comment
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp015.F b/flang/test/Preprocessing/pp015.F
index 700da10a743e..f672841606ec 100644
--- a/flang/test/Preprocessing/pp015.F
+++ b/flang/test/Preprocessing/pp015.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call split between name and (, clipped
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp016.F b/flang/test/Preprocessing/pp016.F
index c5d90e7e2ffb..2170cde03dbb 100644
--- a/flang/test/Preprocessing/pp016.F
+++ b/flang/test/Preprocessing/pp016.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call split between name and ( and in argument
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp017.F b/flang/test/Preprocessing/pp017.F
index 49fff58cdbb4..d4fb0922efbc 100644
--- a/flang/test/Preprocessing/pp017.F
+++ b/flang/test/Preprocessing/pp017.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
+! CHECK: if (777 .eq. 777) then
 * KLM rescan
       integer, parameter :: KWM = 666, KWM2 = 667
 #define KWM2 777

diff  --git a/flang/test/Preprocessing/pp018.F b/flang/test/Preprocessing/pp018.F
index d6a42160404c..6878384a674e 100644
--- a/flang/test/Preprocessing/pp018.F
+++ b/flang/test/Preprocessing/pp018.F
@@ -1,11 +1,11 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm2.eq.777)then
+! CHECK: if (KWM2 .eq. 777) then
 * KLM rescan with #undef (so rescan is after expansion)
       integer, parameter :: KWM2 = 777, KWM = 667
 #define KWM2 666
 #define KWM KWM2
 #undef KWM2
-      if (KWM .eq. 777) then
+      if (KWM  .eq. 777) then
         print *, 'pp018.F yes'
       else
         print *, 'pp018.F no: ', KWM

diff  --git a/flang/test/Preprocessing/pp019.F b/flang/test/Preprocessing/pp019.F
index a8c0ff6b598e..2769e05e3dc9 100644
--- a/flang/test/Preprocessing/pp019.F
+++ b/flang/test/Preprocessing/pp019.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM rescan
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp020.F b/flang/test/Preprocessing/pp020.F
index 9fe9630a81c2..333f171c694c 100644
--- a/flang/test/Preprocessing/pp020.F
+++ b/flang/test/Preprocessing/pp020.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((111)+666)
+! CHECK: res = ((111)+666)
 * FLM expansion of argument
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp021.F b/flang/test/Preprocessing/pp021.F
index 2936264f6c9c..01fbf8624533 100644
--- a/flang/test/Preprocessing/pp021.F
+++ b/flang/test/Preprocessing/pp021.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: ch='KWM'
-! CHECK: if(ch.eq.'KWM')then
+! CHECK: ch = 'KWM'
+! CHECK: if (ch .eq. 'KWM') then
 * KWM NOT expanded in 'literal'
 #define KWM 666
       character(len=3) :: ch

diff  --git a/flang/test/Preprocessing/pp022.F b/flang/test/Preprocessing/pp022.F
index 647b683ec5bc..e940efa3fb9d 100644
--- a/flang/test/Preprocessing/pp022.F
+++ b/flang/test/Preprocessing/pp022.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: ch="KWM"
-! CHECK: if(ch.eq.'KWM')then
+! CHECK: ch = "KWM"
+! CHECK: if (ch .eq. 'KWM') then
 * KWM NOT expanded in "literal"
 #define KWM 666
       character(len=3) :: ch

diff  --git a/flang/test/Preprocessing/pp023.F b/flang/test/Preprocessing/pp023.F
index ecad31b57b6a..750df5cc73e5 100644
--- a/flang/test/Preprocessing/pp023.F
+++ b/flang/test/Preprocessing/pp023.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: ch=3hKWM
-! CHECK: if(ch.eq.'KWM')then
+! CHECK: ch = 3HKWM
+! CHECK: if (ch .eq. 'KWM') then
 * KWM NOT expanded in 9HHOLLERITH literal
 #define KWM 666
 #define HKWM 667

diff  --git a/flang/test/Preprocessing/pp024.F b/flang/test/Preprocessing/pp024.F
index 7f8e3bb99083..6316fec49b59 100644
--- a/flang/test/Preprocessing/pp024.F
+++ b/flang/test/Preprocessing/pp024.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: 100format(3hKWM)
-! CHECK: if(ch.eq.'KWM')then
+! CHECK: 100   format(3HKWM)
+! CHECK: if (ch .eq. 'KWM') then
 * KWM NOT expanded in Hollerith in FORMAT
 #define KWM 666
 #define HKWM 667

diff  --git a/flang/test/Preprocessing/pp025.F b/flang/test/Preprocessing/pp025.F
index bb7bc212776b..99f92afbf88c 100644
--- a/flang/test/Preprocessing/pp025.F
+++ b/flang/test/Preprocessing/pp025.F
@@ -1,10 +1,10 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=ikwm2z
+! CHECK: res = I KWM2 Z
 * KWM expansion is before token pasting due to fixed-form space removal
       integer, parameter :: IKWM2Z = 777
 #define KWM KWM2
       integer :: res
-      res = I KWM Z
+      res = I KWM  Z
       if (res .eq. 777) then
         print *, 'pp025.F yes'
       else

diff  --git a/flang/test/Preprocessing/pp026.F b/flang/test/Preprocessing/pp026.F
index e37700129e9c..18e566286eba 100644
--- a/flang/test/Preprocessing/pp026.F
+++ b/flang/test/Preprocessing/pp026.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((111)+666)
+! CHECK: res = ((111)+666)
 * ## token pasting works in FLM
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp027.F b/flang/test/Preprocessing/pp027.F
index 577bd48b0da3..1d736c962dc0 100644
--- a/flang/test/Preprocessing/pp027.F
+++ b/flang/test/Preprocessing/pp027.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: kwm=666
-! CHECK: if(777.eq.777)then
+! CHECK: KWM = 666
+! CHECK: if (777 .eq. 777) then
 * #DEFINE works in fixed form
       integer, parameter :: KWM = 666
 #DEFINE KWM 777

diff  --git a/flang/test/Preprocessing/pp028.F b/flang/test/Preprocessing/pp028.F
index 3530628d5c50..b85336159c7b 100644
--- a/flang/test/Preprocessing/pp028.F
+++ b/flang/test/Preprocessing/pp028.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=kw
+! CHECK: res =                                                           KW
 * fixed-form clipping done before KWM expansion on source line
       integer, parameter :: KW = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp029.F b/flang/test/Preprocessing/pp029.F
index 23c0d337ad92..4ca87dd20f15 100644
--- a/flang/test/Preprocessing/pp029.F
+++ b/flang/test/Preprocessing/pp029.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
+! CHECK: if (777 .eq. 777) then
 * \ newline allowed in #define
       integer, parameter :: KWM = 666
 #define KWM 77\

diff  --git a/flang/test/Preprocessing/pp030.F b/flang/test/Preprocessing/pp030.F
index 91b12178281d..9643fc0e33ad 100644
--- a/flang/test/Preprocessing/pp030.F
+++ b/flang/test/Preprocessing/pp030.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
+! CHECK: if (777 .eq. 777) then
 * /* C comment */ erased from #define
       integer, parameter :: KWM = 666
 #define KWM 777 /* C comment */

diff  --git a/flang/test/Preprocessing/pp031.F b/flang/test/Preprocessing/pp031.F
index d8286169c02f..4813c40208a9 100644
--- a/flang/test/Preprocessing/pp031.F
+++ b/flang/test/Preprocessing/pp031.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777//ccomment.eq.777)then
-! CHECK: print*,'pp031.F no: ',777//ccomment
+! CHECK: if (777//Ccomment.eq.777)then
+! CHECK: print *, 'pp031.F no: ', 777//Ccomment
 *  // C++ comment NOT erased from #define
       integer, parameter :: KWM = 666
 #define KWM 777 // C comment

diff  --git a/flang/test/Preprocessing/pp032.F b/flang/test/Preprocessing/pp032.F
index 22350e7349f6..bc59bb74605c 100644
--- a/flang/test/Preprocessing/pp032.F
+++ b/flang/test/Preprocessing/pp032.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
-! CHECK: print*,'pp032.F no: ',777
+! CHECK: if (777 .eq. 777) then
+! CHECK: print *, 'pp032.F no: ', 777
 * /* C comment */ \ newline erased from #define
       integer, parameter :: KWM = 666
 #define KWM 77/* C comment */\

diff  --git a/flang/test/Preprocessing/pp033.F b/flang/test/Preprocessing/pp033.F
index 1b32ae6d90ca..67f40bfd458f 100644
--- a/flang/test/Preprocessing/pp033.F
+++ b/flang/test/Preprocessing/pp033.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
-! CHECK: print*,'pp033.F no: ',777
+! CHECK: if (777 .eq. 777) then
+! CHECK: print *, 'pp033.F no: ', 777
 * /* C comment \ newline */ erased from #define
       integer, parameter :: KWM = 666
 #define KWM 77/* C comment \

diff  --git a/flang/test/Preprocessing/pp034.F b/flang/test/Preprocessing/pp034.F
index d9f8a72ec74a..f3f769fe7e42 100644
--- a/flang/test/Preprocessing/pp034.F
+++ b/flang/test/Preprocessing/pp034.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
-! CHECK: print*,'pp034.F no: ',777
+! CHECK: if (777 .eq. 777) then
+! CHECK: print *, 'pp034.F no: ', 777
 * \ newline allowed in name on KWM definition
       integer, parameter :: KWMC = 666
 #define KWM\

diff  --git a/flang/test/Preprocessing/pp035.F b/flang/test/Preprocessing/pp035.F
index 0c0152a3df38..c324fb60b3b0 100644
--- a/flang/test/Preprocessing/pp035.F
+++ b/flang/test/Preprocessing/pp035.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777.eq.777)then
-! CHECK: print*,'pp035.F no: ',777
+! CHECK: if (777 .eq. 777) then
+! CHECK: print *, 'pp035.F no: ', 777
 * #if 2 .LT. 3 works
       integer, parameter :: KWM = 666
 #if 2 .LT. 3

diff  --git a/flang/test/Preprocessing/pp036.F b/flang/test/Preprocessing/pp036.F
index 7894255dfb3b..47aefead2f2c 100644
--- a/flang/test/Preprocessing/pp036.F
+++ b/flang/test/Preprocessing/pp036.F
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(.true.)then
-! CHECK: print*,'pp036.F no: ',.true.
+! CHECK: if (.TRUE .) then
+! CHECK: print *, 'pp036.F no: ', .TRUE .
 * #define FALSE TRUE ...  .FALSE. -> .TRUE.
 #define FALSE TRUE
       if (.FALSE.) then

diff  --git a/flang/test/Preprocessing/pp037.F b/flang/test/Preprocessing/pp037.F
index 93c9b28e4d38..336d5196dea4 100644
--- a/flang/test/Preprocessing/pp037.F
+++ b/flang/test/Preprocessing/pp037.F
@@ -1,12 +1,12 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(7777.eq.777)then
-! CHECK: print*,'pp037.F no: ',7777
+! CHECK: if (7777 .eq. 777) then
+! CHECK: print *, 'pp037.F no: ', 7777
 * fixed-form clipping NOT applied to #define
       integer, parameter :: KWM = 666
 *        1         2         3         4         5         6         7
 *234567890123456789012345678901234567890123456789012345678901234567890123
 #define KWM                                                          7777
-      if (KWM .eq. 777) then
+      if (KWM  .eq. 777) then
         print *, 'pp037.F yes'
       else
         print *, 'pp037.F no: ', KWM

diff  --git a/flang/test/Preprocessing/pp038.F b/flang/test/Preprocessing/pp038.F
index 655551b7a9c6..e61c47d7cee5 100644
--- a/flang/test/Preprocessing/pp038.F
+++ b/flang/test/Preprocessing/pp038.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=((666)+111)
+! CHECK: res = ((666)+111)
 * FLM call with closing ')' on next line (not a continuation)
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp039.F b/flang/test/Preprocessing/pp039.F
index f80e0b074007..b7fd99ba1f3f 100644
--- a/flang/test/Preprocessing/pp039.F
+++ b/flang/test/Preprocessing/pp039.F
@@ -1,7 +1,7 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res=iflm
+! CHECK: res = IFLM
 ! CHECK: (666)
-! CHECK-NOT: res=((666)+111)
+! CHECK-NOT: res = ((666)+111)
 * FLM call with '(' on next line (not a continuation)
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp041.F b/flang/test/Preprocessing/pp041.F
index 9bc04db1e901..3f1f3c6a2aeb 100644
--- a/flang/test/Preprocessing/pp041.F
+++ b/flang/test/Preprocessing/pp041.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: j=666wmj=j+1wm211
+! CHECK: j = 666WMj=j+1WM211
 * use KWM expansion as continuation indicators
 #define KWM 0
 #define KWM2 1

diff  --git a/flang/test/Preprocessing/pp043.F b/flang/test/Preprocessing/pp043.F
index d8ed6b199bf1..cad7e28a31f8 100644
--- a/flang/test/Preprocessing/pp043.F
+++ b/flang/test/Preprocessing/pp043.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm.eq.777)then
+! CHECK: if (KWM .eq. 777) then
 * #define with # in column 6 is a continuation line in fixed-form
       integer, parameter :: defineKWM666 = 555
       integer, parameter :: KWM =

diff  --git a/flang/test/Preprocessing/pp044.F b/flang/test/Preprocessing/pp044.F
index a699c08a2e4f..6304fa4290b2 100644
--- a/flang/test/Preprocessing/pp044.F
+++ b/flang/test/Preprocessing/pp044.F
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK-NOT:z=111
+! CHECK-NOT:z = 111
 * #define directive amid continuations
       integer, parameter :: KWM = 222, KWM111 = 333, KWM222 = 555
       integer, parameter :: KWMKWM = 333

diff  --git a/flang/test/Preprocessing/pp101.F90 b/flang/test/Preprocessing/pp101.F90
index dbf2aa9bc30d..b19b139ebb3c 100644
--- a/flang/test/Preprocessing/pp101.F90
+++ b/flang/test/Preprocessing/pp101.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK:  if(777 .eq. 777) then
+! CHECK:  if (777 .eq. 777) then
 ! keyword macros
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp102.F90 b/flang/test/Preprocessing/pp102.F90
index 73d931ad1511..843f0f10bbb5 100644
--- a/flang/test/Preprocessing/pp102.F90
+++ b/flang/test/Preprocessing/pp102.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm .eq. 777) then
+! CHECK: if (KWM .eq. 777) then
 ! #undef
       integer, parameter :: KWM = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp104.F90 b/flang/test/Preprocessing/pp104.F90
index 95653ff0f2aa..65d8c3895ac4 100644
--- a/flang/test/Preprocessing/pp104.F90
+++ b/flang/test/Preprocessing/pp104.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm .eq. 777) then
+! CHECK: if (kwm .eq. 777) then
 ! KWMs case-sensitive
       integer, parameter :: KWM = 777
 #define KWM 666

diff  --git a/flang/test/Preprocessing/pp107.F90 b/flang/test/Preprocessing/pp107.F90
index 51aa750b8d23..7a78e7548c87 100644
--- a/flang/test/Preprocessing/pp107.F90
+++ b/flang/test/Preprocessing/pp107.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = kwm
+! CHECK: res = KWM
 ! KWM call name split across continuation, no leading &, with & ! comment
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp108.F90 b/flang/test/Preprocessing/pp108.F90
index d891bf3db5e2..8e738142c079 100644
--- a/flang/test/Preprocessing/pp108.F90
+++ b/flang/test/Preprocessing/pp108.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = kwm
+! CHECK: res = KWM
 ! ditto, but without & ! comment
       integer, parameter :: KWM = 666
 #define KWM 777

diff  --git a/flang/test/Preprocessing/pp111.F90 b/flang/test/Preprocessing/pp111.F90
index b0b1219cfca5..4da45ef35f5c 100644
--- a/flang/test/Preprocessing/pp111.F90
+++ b/flang/test/Preprocessing/pp111.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm (666)
+! CHECK: res = IFLM (666)
 ! FLM call name split across continuation, no leading &, with & ! comment
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp112.F90 b/flang/test/Preprocessing/pp112.F90
index 1a3cf3f53151..16705527f68c 100644
--- a/flang/test/Preprocessing/pp112.F90
+++ b/flang/test/Preprocessing/pp112.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm (666)
+! CHECK: res = IFLM (666)
 ! ditto, but without & ! comment
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp115.F90 b/flang/test/Preprocessing/pp115.F90
index 29b580241f38..4e4c621110ed 100644
--- a/flang/test/Preprocessing/pp115.F90
+++ b/flang/test/Preprocessing/pp115.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm (666)
+! CHECK: res = IFLM (666)
 ! ditto, with & ! comment, no leading &
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp116.F90 b/flang/test/Preprocessing/pp116.F90
index 9e070bac6bca..e35a13cbf648 100644
--- a/flang/test/Preprocessing/pp116.F90
+++ b/flang/test/Preprocessing/pp116.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm (666)
+! CHECK: res = IFLM (666)
 ! FLM call split between name and (, no leading &
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp117.F90 b/flang/test/Preprocessing/pp117.F90
index bb0692cd0b7b..d0061a23dbe6 100644
--- a/flang/test/Preprocessing/pp117.F90
+++ b/flang/test/Preprocessing/pp117.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777 .eq. 777) then
+! CHECK: if (777 .eq. 777) then
 ! KWM rescan
       integer, parameter :: KWM = 666, KWM2 = 667
 #define KWM2 777

diff  --git a/flang/test/Preprocessing/pp118.F90 b/flang/test/Preprocessing/pp118.F90
index fe24d83406b5..8ac32ad3dbef 100644
--- a/flang/test/Preprocessing/pp118.F90
+++ b/flang/test/Preprocessing/pp118.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(kwm2 .eq. 777) then
+! CHECK: if (KWM2 .eq. 777) then
 ! KWM rescan with #undef, proving rescan after expansion
       integer, parameter :: KWM2 = 777, KWM = 667
 #define KWM2 666

diff  --git a/flang/test/Preprocessing/pp121.F90 b/flang/test/Preprocessing/pp121.F90
index 900e255d50c6..41487de8b715 100644
--- a/flang/test/Preprocessing/pp121.F90
+++ b/flang/test/Preprocessing/pp121.F90
@@ -1,6 +1,6 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
 ! CHECK: ch = 'KWM'
-! CHECK: if(ch .eq. 'KWM') then
+! CHECK: if (ch .eq. 'KWM') then
 ! KWM NOT expanded in 'literal'
 #define KWM 666
       character(len=3) :: ch

diff  --git a/flang/test/Preprocessing/pp123.F90 b/flang/test/Preprocessing/pp123.F90
index 8181b683a569..0d5cf016f536 100644
--- a/flang/test/Preprocessing/pp123.F90
+++ b/flang/test/Preprocessing/pp123.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: ch = 3hKWM
+! CHECK: ch = 3HKWM
 ! KWM NOT expanded in Hollerith literal
 #define KWM 666
 #define HKWM 667

diff  --git a/flang/test/Preprocessing/pp124.F90 b/flang/test/Preprocessing/pp124.F90
index 750f9facd279..1bb48c2d3ac1 100644
--- a/flang/test/Preprocessing/pp124.F90
+++ b/flang/test/Preprocessing/pp124.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: 100 format(3hKWM)
+! CHECK: 100 format(3HKWM)
 ! KWM NOT expanded in Hollerith in FORMAT
 #define KWM 666
 #define HKWM 667

diff  --git a/flang/test/Preprocessing/pp125.F90 b/flang/test/Preprocessing/pp125.F90
index 86abccca7b4e..8f9c8f87365d 100644
--- a/flang/test/Preprocessing/pp125.F90
+++ b/flang/test/Preprocessing/pp125.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777 .eq. 777) then
+! CHECK: if (777 .eq. 777) then
 ! #DEFINE works in free form
       integer, parameter :: KWM = 666
 #DEFINE KWM 777

diff  --git a/flang/test/Preprocessing/pp126.F90 b/flang/test/Preprocessing/pp126.F90
index f41af1e1b1cf..6e790c8fbd45 100644
--- a/flang/test/Preprocessing/pp126.F90
+++ b/flang/test/Preprocessing/pp126.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: if(777 .eq. 777) then
+! CHECK: if (777 .eq. 777) then
 ! \ newline works in #define
       integer, parameter :: KWM = 666
 #define KWM 77\

diff  --git a/flang/test/Preprocessing/pp127.F90 b/flang/test/Preprocessing/pp127.F90
index 09de8ede986b..03d2236b74af 100644
--- a/flang/test/Preprocessing/pp127.F90
+++ b/flang/test/Preprocessing/pp127.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm(666 )
+! CHECK: res = IFLM(666 )
 ! FLM call with closing ')' on next line (not a continuation)
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/test/Preprocessing/pp128.F90 b/flang/test/Preprocessing/pp128.F90
index a8bc79227aaa..657827f73d81 100644
--- a/flang/test/Preprocessing/pp128.F90
+++ b/flang/test/Preprocessing/pp128.F90
@@ -1,5 +1,5 @@
 ! RUN: %flang -E %s 2>&1 | FileCheck %s
-! CHECK: res = iflm
+! CHECK: res = IFLM
 ! FLM call with '(' on next line (not a continuation)
       integer function IFLM(x)
         integer :: x

diff  --git a/flang/tools/f18-parse-demo/f18-parse-demo.cpp b/flang/tools/f18-parse-demo/f18-parse-demo.cpp
index 2033ef6c3bc2..2c44b90c72aa 100644
--- a/flang/tools/f18-parse-demo/f18-parse-demo.cpp
+++ b/flang/tools/f18-parse-demo/f18-parse-demo.cpp
@@ -87,9 +87,10 @@ struct DriverOptions {
   bool warnOnNonstandardUsage{false}; // -Mstandard
   bool warningsAreErrors{false}; // -Werror
   Fortran::parser::Encoding encoding{Fortran::parser::Encoding::LATIN_1};
+  bool lineDirectives{true}; // -P disables
   bool syntaxOnly{false};
   bool dumpProvenance{false};
-  bool dumpCookedChars{false};
+  bool noReformat{false}; // -E -fno-reformat
   bool dumpUnparse{false};
   bool dumpParseTree{false};
   bool timeParse{false};
@@ -176,8 +177,13 @@ std::string CompileFortran(
     parsing.DumpProvenance(llvm::outs());
     return {};
   }
-  if (driver.dumpCookedChars) {
-    parsing.DumpCookedChars(llvm::outs());
+  if (options.prescanAndReformat) {
+    parsing.messages().Emit(llvm::errs(), allCookedSources);
+    if (driver.noReformat) {
+      parsing.DumpCookedChars(llvm::outs());
+    } else {
+      parsing.EmitPreprocessedSource(llvm::outs(), driver.lineDirectives);
+    }
     return {};
   }
   parsing.Parse(llvm::outs());
@@ -302,7 +308,7 @@ int main(int argc, char *const argv[]) {
   while (!args.empty()) {
     std::string arg{std::move(args.front())};
     args.pop_front();
-    if (arg.empty()) {
+    if (arg.empty() || arg == "-Xflang") {
     } else if (arg.at(0) != '-') {
       anyFiles = true;
       auto dot{arg.rfind(".")};
@@ -353,8 +359,12 @@ int main(int argc, char *const argv[]) {
       driver.warningsAreErrors = true;
     } else if (arg == "-ed") {
       options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
-    } else if (arg == "-E" || arg == "-fpreprocess-only") {
-      driver.dumpCookedChars = true;
+    } else if (arg == "-E") {
+      options.prescanAndReformat = true;
+    } else if (arg == "-P") {
+      driver.lineDirectives = false;
+    } else if (arg == "-fno-reformat") {
+      driver.noReformat = true;
     } else if (arg == "-fbackslash") {
       options.features.Enable(
           Fortran::common::LanguageFeature::BackslashEscapes);

diff  --git a/flang/tools/f18/f18.cpp b/flang/tools/f18/f18.cpp
index 4fe5d1a99a3f..3748adb6d574 100644
--- a/flang/tools/f18/f18.cpp
+++ b/flang/tools/f18/f18.cpp
@@ -93,9 +93,10 @@ struct DriverOptions {
   bool warningsAreErrors{false}; // -Werror
   bool byteswapio{false}; // -byteswapio
   Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
+  bool lineDirectives{true}; // -P disables
   bool syntaxOnly{false};
   bool dumpProvenance{false};
-  bool dumpCookedChars{false};
+  bool noReformat{false}; // -E -fno-reformat
   bool dumpUnparse{false};
   bool dumpUnparseWithSymbols{false};
   bool dumpParseTree{false};
@@ -221,9 +222,13 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options,
     parsing.DumpProvenance(llvm::outs());
     return {};
   }
-  if (driver.dumpCookedChars) {
+  if (options.prescanAndReformat) {
     parsing.messages().Emit(llvm::errs(), allCookedSources);
-    parsing.DumpCookedChars(llvm::outs());
+    if (driver.noReformat) {
+      parsing.DumpCookedChars(llvm::outs());
+    } else {
+      parsing.EmitPreprocessedSource(llvm::outs(), driver.lineDirectives);
+    }
     return {};
   }
   parsing.Parse(llvm::outs());
@@ -471,7 +476,7 @@ int main(int argc, char *const argv[]) {
     std::string suffix{arg.substr(dot + 1)};
     std::string prefix{arg.substr(0, 2)};
     args.pop_front();
-    if (arg.empty()) {
+    if (arg.empty() || arg == "-Xflang") {
     } else if (arg.at(0) != '-') {
       anyFiles = true;
       if (dot == std::string::npos) {
@@ -512,7 +517,8 @@ int main(int argc, char *const argv[]) {
     } else if (arg == "-Munlimited" || arg == "-ffree-line-length-none" ||
         arg == "-ffree-line-length-0" || arg == "-ffixed-line-length-none" ||
         arg == "-ffixed-line-length-0") {
-      // For reparsing f18's -E output of fixed-form cooked character stream
+      // For reparsing f18's -E -fno-reformat output of fixed-form
+      // cooked character stream
       options.fixedFormColumns = 1000000;
     } else if (arg == "-Mbackslash") {
       options.features.Enable(
@@ -536,7 +542,11 @@ int main(int argc, char *const argv[]) {
     } else if (arg == "-ed") {
       options.features.Enable(Fortran::common::LanguageFeature::OldDebugLines);
     } else if (arg == "-E") {
-      driver.dumpCookedChars = true;
+      options.prescanAndReformat = true;
+    } else if (arg == "-P") {
+      driver.lineDirectives = false;
+    } else if (arg == "-fno-reformat") {
+      driver.noReformat = true;
     } else if (arg == "-fbackslash" || arg == "-fno-backslash") {
       options.features.Enable(
           Fortran::common::LanguageFeature::BackslashEscapes,

diff  --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index 150f20d9b269..b706637a6c92 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -1,4 +1,4 @@
-//===- unittests/Frontend/PrintPreprocessedTest.cpp  FrontendAction tests--===//
+//===- unittests/Frontend/FrontendActionTest.cpp  FrontendAction tests-----===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -116,6 +116,7 @@ TEST_F(FrontendActionTest, PrintPreprocessedInput) {
 
   // Set-up the action kind.
   compInst_.invocation().frontendOpts().programAction_ = PrintPreprocessedInput;
+  compInst_.invocation().preprocessorOpts().noReformat = true;
 
   // Set-up the output stream. We are using output buffer wrapped as an output
   // stream, as opposed to an actual file (or a file descriptor).


        


More information about the cfe-commits mailing list