Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -701,7 +701,7 @@ def O : Joined<["-"], "O">, Group, Flags<[CC1Option]>; def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["1"]>; def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>; -def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group, +def P : Flag<["-"], "P">, Flags<[CC1Option,FlangOption,FC1Option]>, Group, HelpText<"Disable linemarker output in -E mode">, MarshallingInfoNegativeFlag>; def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>, @@ -4567,7 +4567,7 @@ HelpText<"Measure the parse tree">; def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, 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, HelpText<"Dump symbols and their source code locations">; @@ -4579,7 +4579,8 @@ def fno_analyzed_objects_for_unparse : Flag<["-"], "fno-analyzed-objects-for-unparse">, Group, HelpText<"Do not use the analyzed objects when unparsing">; - +def fno_reformat : Flag<["-"], "fno-reformat">, Group, + HelpText<"Dump the cooked character stream in -E mode">; } //===----------------------------------------------------------------------===// Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -37,8 +37,9 @@ 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 { Index: flang/include/flang/Frontend/FrontendOptions.h =================================================================== --- flang/include/flang/Frontend/FrontendOptions.h +++ flang/include/flang/Frontend/FrontendOptions.h @@ -25,7 +25,7 @@ /// -test-io mode InputOutputTest, - /// -E mode. + /// -E mode PrintPreprocessedInput, /// -fsyntax-only Index: flang/include/flang/Frontend/PreprocessorOptions.h =================================================================== --- flang/include/flang/Frontend/PreprocessorOptions.h +++ flang/include/flang/Frontend/PreprocessorOptions.h @@ -44,6 +44,28 @@ PPMacrosFlag macrosFlag_ = PPMacrosFlag::Unknown; +public: + // -P: Suppress #line directives in -E output + bool noLineDirectives() const { return noLineDirectives_; } + PreprocessorOptions &set_noLineDirectives(bool yes = true) { + noLineDirectives_ = yes; + return *this; + } + +private: + bool noLineDirectives_{false}; + +public: + // -fno-reformat: Emit cooked character stream as -E output + bool noReformat() const { return noReformat_; } + PreprocessorOptions &set_noReformat(bool yes = true) { + noReformat_ = yes; + return *this; + } + +private: + bool noReformat_{false}; + public: PreprocessorOptions() {} Index: flang/include/flang/Parser/parsing.h =================================================================== --- flang/include/flang/Parser/parsing.h +++ flang/include/flang/Parser/parsing.h @@ -37,6 +37,7 @@ 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 @@ 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 &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; Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -371,6 +371,9 @@ (currentArg->getOption().matches(clang::driver::options::OPT_cpp)) ? PPMacrosFlag::Include : PPMacrosFlag::Exclude; + + opts.set_noReformat(args.hasArg(clang::driver::options::OPT_fno_reformat)); + opts.set_noLineDirectives(args.hasArg(clang::driver::options::OPT_P)); } /// Parses all semantic related arguments and populates the variables Index: flang/lib/Frontend/FrontendActions.cpp =================================================================== --- flang/lib/Frontend/FrontendActions.cpp +++ flang/lib/Frontend/FrontendActions.cpp @@ -208,9 +208,14 @@ 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 @@ 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 @@ (*os) << outForPP.str(); } else { llvm::errs() << "Unable to create the output file\n"; - return; } } Index: flang/lib/Frontend/FrontendOptions.cpp =================================================================== --- flang/lib/Frontend/FrontendOptions.cpp +++ flang/lib/Frontend/FrontendOptions.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "flang/Frontend/FrontendOptions.h" -#include "flang/Evaluate/expression.h" using namespace Fortran::frontend; Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp =================================================================== --- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -28,61 +28,43 @@ switch (ak) { case InputOutputTest: return std::make_unique(); - break; case PrintPreprocessedInput: return std::make_unique(); - break; case ParseSyntaxOnly: return std::make_unique(); case EmitObj: return std::make_unique(); - break; case DebugUnparse: return std::make_unique(); - break; case DebugUnparseNoSema: return std::make_unique(); - break; case DebugUnparseWithSymbols: return std::make_unique(); - break; case DebugDumpSymbols: return std::make_unique(); - break; case DebugDumpParseTree: return std::make_unique(); - break; case DebugDumpParseTreeNoSema: return std::make_unique(); - break; case DebugDumpAll: return std::make_unique(); - break; case DebugDumpProvenance: return std::make_unique(); - break; case DebugDumpParsingLog: return std::make_unique(); - break; case DebugMeasureParseTree: return std::make_unique(); - break; case DebugPreFIRTree: return std::make_unique(); - break; case GetDefinition: return std::make_unique(); - break; case GetSymbolsSources: return std::make_unique(); - break; case InitOnly: return std::make_unique(); - break; default: break; // TODO: - // case RunPreprocessor: // case ParserSyntaxOnly: // case EmitLLVM: // case EmitLLVMOnly: Index: flang/lib/Parser/parsing.cpp =================================================================== --- flang/lib/Parser/parsing.cpp +++ flang/lib/Parser/parsing.cpp @@ -95,6 +95,94 @@ 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 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(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()}; Index: flang/lib/Parser/provenance.cpp =================================================================== --- flang/lib/Parser/provenance.cpp +++ flang/lib/Parser/provenance.cpp @@ -593,7 +593,7 @@ return result; } } - return nullptr; + return std::nullopt; } void AllCookedSources::Dump(llvm::raw_ostream &o) const { Index: flang/test/Driver/cpp-nocpp-command-line-macro.f90 =================================================================== --- flang/test/Driver/cpp-nocpp-command-line-macro.f90 +++ flang/test/Driver/cpp-nocpp-command-line-macro.f90 @@ -1,9 +1,9 @@ !----------- ! RUN lines !----------- -! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED -! RUN: %flang_fc1 -E -cpp -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED -! RUN: %flang_fc1 -E -nocpp -DX=A %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED +! RUN: %flang_fc1 -E -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED +! RUN: %flang_fc1 -E -fno-reformat -cpp -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED +! RUN: %flang_fc1 -E -fno-reformat -nocpp -DX=A %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED !----------------- ! EXPECTED OUTPUT Index: flang/test/Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -50,6 +50,7 @@ ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros ! CHECK-NEXT: -o Write output to ! CHECK-NEXT: -pedantic Warn on language extensions +! CHECK-NEXT: -P Disable linemarker output in -E mode ! CHECK-NEXT: -std= Language standard to compile for ! CHECK-NEXT: -U Undefine macro ! CHECK-NEXT: --version Print version information Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -50,6 +50,7 @@ ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros ! HELP-NEXT: -o Write output to ! HELP-NEXT: -pedantic Warn on language extensions +! HELP-NEXT: -P Disable linemarker output in -E mode ! HELP-NEXT: -std= Language standard to compile for ! HELP-NEXT: -U Undefine 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 Write output to ! HELP-FC1-NEXT: -pedantic Warn on language extensions +! HELP-FC1-NEXT: -P Disable linemarker output in -E mode ! HELP-FC1-NEXT: -std= Language standard to compile for ! HELP-FC1-NEXT: -test-io Run the InputOuputTest action. Use for development and testing only. ! HELP-FC1-NEXT: -U Undefine macro Index: flang/test/Driver/escaped-backslash.f90 =================================================================== --- flang/test/Driver/escaped-backslash.f90 +++ flang/test/Driver/escaped-backslash.f90 @@ -3,16 +3,16 @@ !-------------------------- ! FLANG DRIVER (flang-new) !-------------------------- -! RUN: %flang -E %s 2>&1 | FileCheck %s --check-prefix=ESCAPED -! RUN: %flang -E -fbackslash -fno-backslash %s 2>&1 | FileCheck %s --check-prefix=ESCAPED -! RUN: %flang -E -fbackslash %s 2>&1 | FileCheck %s --check-prefix=UNESCAPED +! RUN: %flang -E -Xflang -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=ESCAPED +! RUN: %flang -E -Xflang -fno-reformat -fbackslash -fno-backslash %s 2>&1 | FileCheck %s --check-prefix=ESCAPED +! RUN: %flang -E -Xflang -fno-reformat -fbackslash %s 2>&1 | FileCheck %s --check-prefix=UNESCAPED !----------------------------------------- ! FRONTEND FLANG DRIVER (flang-new -fc1) !----------------------------------------- -! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s --check-prefix=ESCAPED -! RUN: %flang_fc1 -E -fbackslash -fno-backslash %s 2>&1 | FileCheck %s --check-prefix=ESCAPED -! RUN: %flang_fc1 -E -fbackslash %s 2>&1 | FileCheck %s --check-prefix=UNESCAPED +! RUN: %flang_fc1 -E -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=ESCAPED +! RUN: %flang_fc1 -E -fno-reformat -fbackslash -fno-backslash %s 2>&1 | FileCheck %s --check-prefix=ESCAPED +! RUN: %flang_fc1 -E -fno-reformat -fbackslash %s 2>&1 | FileCheck %s --check-prefix=UNESCAPED !----------------------------------------- ! EXPECTED OUTPUT FOR ESCAPED BACKSLASHES Index: flang/test/Driver/fixed-free-detection.f90 =================================================================== --- flang/test/Driver/fixed-free-detection.f90 +++ flang/test/Driver/fixed-free-detection.f90 @@ -5,16 +5,16 @@ !-------------------------- ! 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 Index: flang/test/Driver/fixed-line-length.f90 =================================================================== --- flang/test/Driver/fixed-line-length.f90 +++ 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 Index: flang/test/Driver/frontend-forwarding.f90 =================================================================== --- flang/test/Driver/frontend-forwarding.f90 +++ 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" Index: flang/test/Driver/include-header.f90 =================================================================== --- flang/test/Driver/include-header.f90 +++ flang/test/Driver/include-header.f90 @@ -3,18 +3,18 @@ !-------------------------- ! FLANG DRIVER (flang) !-------------------------- -! RUN: not %flang -E %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED -! RUN: %flang -E -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE -! RUN: %flang -E -I %S/Inputs -I %S/Inputs/header-dir %s 2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY -! RUN: %flang -E -I %S/Inputs/header-dir -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY +! RUN: not %flang -E -Xflang -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED +! RUN: %flang -E -Xflang -fno-reformat -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE +! RUN: %flang -E -Xflang -fno-reformat -I %S/Inputs -I %S/Inputs/header-dir %s 2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY +! RUN: %flang -E -Xflang -fno-reformat -I %S/Inputs/header-dir -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY !---------------------------------------- ! FRONTEND FLANG DRIVER (flang_fc1) !---------------------------------------- -! RUN: not %flang_fc1 -E %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED -! RUN: %flang_fc1 -E -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE -! RUN: %flang_fc1 -E -I %S/Inputs -I %S/Inputs/header-dir %s 2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY -! RUN: %flang_fc1 -E -I %S/Inputs/header-dir -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY +! RUN: not %flang_fc1 -E -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED +! RUN: %flang_fc1 -E -fno-reformat -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE +! RUN: %flang_fc1 -E -fno-reformat -I %S/Inputs -I %S/Inputs/header-dir %s 2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY +! RUN: %flang_fc1 -E -fno-reformat -I %S/Inputs/header-dir -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY !-------------------------------------------- ! EXPECTED OUTPUT FOR MISSING INCLUDED FILE Index: flang/test/Driver/input-from-stdin.f90 =================================================================== --- flang/test/Driver/input-from-stdin.f90 +++ flang/test/Driver/input-from-stdin.f90 @@ -6,21 +6,21 @@ ! FLANG DRIVER (flang) !-------------------------- ! Input type is implicit -! RUN: cat %s | %flang -E -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED -! RUN: cat %s | %flang -DNEW -E -cpp - | FileCheck %s --check-prefix=PP-DEFINED -! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED -! RUN: cat %s | %flang -DNEW -E -nocpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -E -Xflang -fno-reformat -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -DNEW -E -Xflang -fno-reformat -cpp - | FileCheck %s --check-prefix=PP-DEFINED +! RUN: cat %s | %flang -DNEW -E -Xflang -fno-reformat - | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -DNEW -E -Xflang -fno-reformat -nocpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED ! Input type is explicit -! RUN: cat %s | %flang -E -cpp -x f95-cpp-input - | FileCheck %s --check-prefix=PP-NOT-DEFINED -! RUN: cat %s | %flang -DNEW -E -cpp -x f95-cpp-input - | FileCheck %s --check-prefix=PP-DEFINED +! RUN: cat %s | %flang -E -Xflang -fno-reformat -cpp -x f95-cpp-input - | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -DNEW -E -Xflang -fno-reformat -cpp -x f95-cpp-input - | FileCheck %s --check-prefix=PP-DEFINED !--------------------------------------- ! FLANG FRONTEND DRIVER (flang -fc1) !--------------------------------------- ! Test `-E`: for the corresponding frontend actions the driver relies on the prescanner API to handle file I/O -! RUN: cat %s | %flang -fc1 -E -cpp | FileCheck %s --check-prefix=PP-NOT-DEFINED -! RUN: cat %s | %flang -fc1 -DNEW -E -cpp | FileCheck %s --check-prefix=PP-DEFINED +! RUN: cat %s | %flang -fc1 -E -fno-reformat -cpp | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -fc1 -DNEW -E -fno-reformat -cpp | FileCheck %s --check-prefix=PP-DEFINED ! Test `-test-io`: for the corresponding frontend action (`InputOutputTestAction`) the driver handles the file I/O on its own ! the corresponding action (`PrintPreprocessedAction`) Index: flang/test/Driver/macro-def-undef.F90 =================================================================== --- flang/test/Driver/macro-def-undef.F90 +++ flang/test/Driver/macro-def-undef.F90 @@ -3,16 +3,16 @@ !-------------------------- ! 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 -Xflang -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED +! RUN: %flang -E -Xflang -fno-reformat -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED +! RUN: %flang -E -Xflang -fno-reformat -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 -fno-reformat %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED +! RUN: %flang_fc1 -E -fno-reformat -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED +! RUN: %flang_fc1 -E -fno-reformat -DX -UX %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED !-------------------------------------------- ! EXPECTED OUTPUT FOR AN UNDEFINED MACRO Index: flang/test/Driver/macro-multiline.F90 =================================================================== --- flang/test/Driver/macro-multiline.F90 +++ flang/test/Driver/macro-multiline.F90 @@ -5,12 +5,12 @@ !-------------------------- ! 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 -Xflang -fno-reformat %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 -fno-reformat %s 2>&1 | FileCheck --strict-whitespace --match-full-lines %s !------------------------------- ! EXPECTED OUTPUT FOR MACRO 'X' Index: flang/test/Parser/badlabel.f =================================================================== --- flang/test/Parser/badlabel.f +++ 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 Index: flang/test/Preprocessing/assert.F90 =================================================================== --- flang/test/Preprocessing/assert.F90 +++ 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 Index: flang/test/Preprocessing/dash-E.F90 =================================================================== --- /dev/null +++ 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 Index: flang/test/Preprocessing/hollerith.f =================================================================== --- flang/test/Preprocessing/hollerith.f +++ 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 / Index: flang/test/Preprocessing/pp001.F =================================================================== --- flang/test/Preprocessing/pp001.F +++ flang/test/Preprocessing/pp001.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: if(777.eq.777)then * keyword macros integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp002.F =================================================================== --- flang/test/Preprocessing/pp002.F +++ flang/test/Preprocessing/pp002.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: if(kwm.eq.777)then * #undef integer, parameter :: KWM = 777 Index: flang/test/Preprocessing/pp003.F =================================================================== --- flang/test/Preprocessing/pp003.F +++ flang/test/Preprocessing/pp003.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: res=((666)+111) * function-like macros integer function IFLM(x) Index: flang/test/Preprocessing/pp004.F =================================================================== --- flang/test/Preprocessing/pp004.F +++ flang/test/Preprocessing/pp004.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: if(kwm.eq.777)then * KWMs case-sensitive integer, parameter :: KWM = 777 Index: flang/test/Preprocessing/pp005.F =================================================================== --- flang/test/Preprocessing/pp005.F +++ flang/test/Preprocessing/pp005.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: res=777 * KWM split across continuation, implicit padding integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp006.F =================================================================== --- flang/test/Preprocessing/pp006.F +++ flang/test/Preprocessing/pp006.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: res=777 * ditto, but with intervening *comment line integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp007.F =================================================================== --- flang/test/Preprocessing/pp007.F +++ flang/test/Preprocessing/pp007.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: res=kwm * KWM split across continuation, clipped after column 72 integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp008.F =================================================================== --- flang/test/Preprocessing/pp008.F +++ flang/test/Preprocessing/pp008.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: res=kwm * KWM with spaces in name at invocation NOT replaced integer, parameter :: KWM = 777 Index: flang/test/Preprocessing/pp009.F =================================================================== --- flang/test/Preprocessing/pp009.F +++ flang/test/Preprocessing/pp009.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: res=((666)+111) * FLM call split across continuation, implicit padding integer function IFLM(x) Index: flang/test/Preprocessing/pp010.F =================================================================== --- flang/test/Preprocessing/pp010.F +++ flang/test/Preprocessing/pp010.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: res=((666)+111) * ditto, but with intervening *comment line integer function IFLM(x) Index: flang/test/Preprocessing/pp011.F =================================================================== --- flang/test/Preprocessing/pp011.F +++ flang/test/Preprocessing/pp011.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: res=iflm(666) * FLM call name split across continuation, clipped integer function IFLM(x) Index: flang/test/Preprocessing/pp012.F =================================================================== --- flang/test/Preprocessing/pp012.F +++ flang/test/Preprocessing/pp012.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: res=((666)+111) * FLM call name split across continuation integer function IFLM(x) Index: flang/test/Preprocessing/pp013.F =================================================================== --- flang/test/Preprocessing/pp013.F +++ flang/test/Preprocessing/pp013.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: res=((666)+111) * FLM call split between name and ( integer function IFLM(x) Index: flang/test/Preprocessing/pp014.F =================================================================== --- flang/test/Preprocessing/pp014.F +++ flang/test/Preprocessing/pp014.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: res=((666)+111) * FLM call split between name and (, with intervening *comment integer function IFLM(x) Index: flang/test/Preprocessing/pp015.F =================================================================== --- flang/test/Preprocessing/pp015.F +++ flang/test/Preprocessing/pp015.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: res=((666)+111) * FLM call split between name and (, clipped integer function IFLM(x) Index: flang/test/Preprocessing/pp016.F =================================================================== --- flang/test/Preprocessing/pp016.F +++ flang/test/Preprocessing/pp016.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: res=((666)+111) * FLM call split between name and ( and in argument integer function IFLM(x) Index: flang/test/Preprocessing/pp017.F =================================================================== --- flang/test/Preprocessing/pp017.F +++ flang/test/Preprocessing/pp017.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: if(777.eq.777)then * KLM rescan integer, parameter :: KWM = 666, KWM2 = 667 Index: flang/test/Preprocessing/pp018.F =================================================================== --- flang/test/Preprocessing/pp018.F +++ flang/test/Preprocessing/pp018.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: if(kwm2.eq.777)then * KLM rescan with #undef (so rescan is after expansion) integer, parameter :: KWM2 = 777, KWM = 667 Index: flang/test/Preprocessing/pp019.F =================================================================== --- flang/test/Preprocessing/pp019.F +++ flang/test/Preprocessing/pp019.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: res=((666)+111) * FLM rescan integer function IFLM(x) Index: flang/test/Preprocessing/pp020.F =================================================================== --- flang/test/Preprocessing/pp020.F +++ flang/test/Preprocessing/pp020.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: res=((111)+666) * FLM expansion of argument integer function IFLM(x) Index: flang/test/Preprocessing/pp021.F =================================================================== --- flang/test/Preprocessing/pp021.F +++ flang/test/Preprocessing/pp021.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: ch='KWM' ! CHECK: if(ch.eq.'KWM')then * KWM NOT expanded in 'literal' Index: flang/test/Preprocessing/pp022.F =================================================================== --- flang/test/Preprocessing/pp022.F +++ flang/test/Preprocessing/pp022.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: ch="KWM" ! CHECK: if(ch.eq.'KWM')then * KWM NOT expanded in "literal" Index: flang/test/Preprocessing/pp023.F =================================================================== --- flang/test/Preprocessing/pp023.F +++ flang/test/Preprocessing/pp023.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: ch=3hKWM ! CHECK: if(ch.eq.'KWM')then * KWM NOT expanded in 9HHOLLERITH literal Index: flang/test/Preprocessing/pp024.F =================================================================== --- flang/test/Preprocessing/pp024.F +++ flang/test/Preprocessing/pp024.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: 100format(3hKWM) ! CHECK: if(ch.eq.'KWM')then * KWM NOT expanded in Hollerith in FORMAT Index: flang/test/Preprocessing/pp025.F =================================================================== --- flang/test/Preprocessing/pp025.F +++ flang/test/Preprocessing/pp025.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: res=ikwm2z * KWM expansion is before token pasting due to fixed-form space removal integer, parameter :: IKWM2Z = 777 Index: flang/test/Preprocessing/pp026.F =================================================================== --- flang/test/Preprocessing/pp026.F +++ flang/test/Preprocessing/pp026.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: res=((111)+666) * ## token pasting works in FLM integer function IFLM(x) Index: flang/test/Preprocessing/pp027.F =================================================================== --- flang/test/Preprocessing/pp027.F +++ flang/test/Preprocessing/pp027.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: kwm=666 ! CHECK: if(777.eq.777)then * #DEFINE works in fixed form Index: flang/test/Preprocessing/pp028.F =================================================================== --- flang/test/Preprocessing/pp028.F +++ flang/test/Preprocessing/pp028.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: res=kw * fixed-form clipping done before KWM expansion on source line integer, parameter :: KW = 777 Index: flang/test/Preprocessing/pp029.F =================================================================== --- flang/test/Preprocessing/pp029.F +++ flang/test/Preprocessing/pp029.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: if(777.eq.777)then * \ newline allowed in #define integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp030.F =================================================================== --- flang/test/Preprocessing/pp030.F +++ flang/test/Preprocessing/pp030.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: if(777.eq.777)then * /* C comment */ erased from #define integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp031.F =================================================================== --- flang/test/Preprocessing/pp031.F +++ flang/test/Preprocessing/pp031.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: if(777//ccomment.eq.777)then ! CHECK: print*,'pp031.F no: ',777//ccomment * // C++ comment NOT erased from #define Index: flang/test/Preprocessing/pp032.F =================================================================== --- flang/test/Preprocessing/pp032.F +++ flang/test/Preprocessing/pp032.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: if(777.eq.777)then ! CHECK: print*,'pp032.F no: ',777 * /* C comment */ \ newline erased from #define Index: flang/test/Preprocessing/pp033.F =================================================================== --- flang/test/Preprocessing/pp033.F +++ flang/test/Preprocessing/pp033.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: if(777.eq.777)then ! CHECK: print*,'pp033.F no: ',777 * /* C comment \ newline */ erased from #define Index: flang/test/Preprocessing/pp034.F =================================================================== --- flang/test/Preprocessing/pp034.F +++ flang/test/Preprocessing/pp034.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: if(777.eq.777)then ! CHECK: print*,'pp034.F no: ',777 * \ newline allowed in name on KWM definition Index: flang/test/Preprocessing/pp035.F =================================================================== --- flang/test/Preprocessing/pp035.F +++ flang/test/Preprocessing/pp035.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: if(777.eq.777)then ! CHECK: print*,'pp035.F no: ',777 * #if 2 .LT. 3 works Index: flang/test/Preprocessing/pp036.F =================================================================== --- flang/test/Preprocessing/pp036.F +++ flang/test/Preprocessing/pp036.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: if(.true.)then ! CHECK: print*,'pp036.F no: ',.true. * #define FALSE TRUE ... .FALSE. -> .TRUE. Index: flang/test/Preprocessing/pp037.F =================================================================== --- flang/test/Preprocessing/pp037.F +++ flang/test/Preprocessing/pp037.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: if(7777.eq.777)then ! CHECK: print*,'pp037.F no: ',7777 * fixed-form clipping NOT applied to #define Index: flang/test/Preprocessing/pp038.F =================================================================== --- flang/test/Preprocessing/pp038.F +++ flang/test/Preprocessing/pp038.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: res=((666)+111) * FLM call with closing ')' on next line (not a continuation) integer function IFLM(x) Index: flang/test/Preprocessing/pp039.F =================================================================== --- flang/test/Preprocessing/pp039.F +++ flang/test/Preprocessing/pp039.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: res=iflm ! CHECK: (666) ! CHECK-NOT: res=((666)+111) Index: flang/test/Preprocessing/pp040.F =================================================================== --- flang/test/Preprocessing/pp040.F +++ flang/test/Preprocessing/pp040.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-NOT: FAIL HARD! * #define KWM c, then KWM works as comment line initiator #define KWM c Index: flang/test/Preprocessing/pp041.F =================================================================== --- flang/test/Preprocessing/pp041.F +++ flang/test/Preprocessing/pp041.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: j=666wmj=j+1wm211 * use KWM expansion as continuation indicators #define KWM 0 Index: flang/test/Preprocessing/pp042.F =================================================================== --- flang/test/Preprocessing/pp042.F +++ flang/test/Preprocessing/pp042.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-NOT: goto 2 * #define c 1, then use c as label in fixed-form #define c 1 Index: flang/test/Preprocessing/pp043.F =================================================================== --- flang/test/Preprocessing/pp043.F +++ flang/test/Preprocessing/pp043.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: if(kwm.eq.777)then * #define with # in column 6 is a continuation line in fixed-form integer, parameter :: defineKWM666 = 555 Index: flang/test/Preprocessing/pp044.F =================================================================== --- flang/test/Preprocessing/pp044.F +++ flang/test/Preprocessing/pp044.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-NOT:z=111 * #define directive amid continuations integer, parameter :: KWM = 222, KWM111 = 333, KWM222 = 555 Index: flang/test/Preprocessing/pp101.F90 =================================================================== --- flang/test/Preprocessing/pp101.F90 +++ flang/test/Preprocessing/pp101.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(777 .eq. 777) then ! keyword macros integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp102.F90 =================================================================== --- flang/test/Preprocessing/pp102.F90 +++ flang/test/Preprocessing/pp102.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(kwm .eq. 777) then ! #undef integer, parameter :: KWM = 777 Index: flang/test/Preprocessing/pp103.F90 =================================================================== --- flang/test/Preprocessing/pp103.F90 +++ flang/test/Preprocessing/pp103.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: res = ((666)+111) ! function-like macros integer function IFLM(x) Index: flang/test/Preprocessing/pp104.F90 =================================================================== --- flang/test/Preprocessing/pp104.F90 +++ flang/test/Preprocessing/pp104.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(kwm .eq. 777) then ! KWMs case-sensitive integer, parameter :: KWM = 777 Index: flang/test/Preprocessing/pp105.F90 =================================================================== --- flang/test/Preprocessing/pp105.F90 +++ flang/test/Preprocessing/pp105.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: res = 777 ! KWM call name split across continuation, with leading & integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp106.F90 =================================================================== --- flang/test/Preprocessing/pp106.F90 +++ flang/test/Preprocessing/pp106.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: res = 777 ! ditto, with & ! comment integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp107.F90 =================================================================== --- flang/test/Preprocessing/pp107.F90 +++ flang/test/Preprocessing/pp107.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: res = kwm ! KWM call name split across continuation, no leading &, with & ! comment integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp108.F90 =================================================================== --- flang/test/Preprocessing/pp108.F90 +++ flang/test/Preprocessing/pp108.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: res = kwm ! ditto, but without & ! comment integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp109.F90 =================================================================== --- flang/test/Preprocessing/pp109.F90 +++ flang/test/Preprocessing/pp109.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: res = ((666)+111) ! FLM call name split with leading & integer function IFLM(x) Index: flang/test/Preprocessing/pp110.F90 =================================================================== --- flang/test/Preprocessing/pp110.F90 +++ flang/test/Preprocessing/pp110.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: res = ((666)+111) ! ditto, with & ! comment integer function IFLM(x) Index: flang/test/Preprocessing/pp111.F90 =================================================================== --- flang/test/Preprocessing/pp111.F90 +++ flang/test/Preprocessing/pp111.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: res = iflm (666) ! FLM call name split across continuation, no leading &, with & ! comment integer function IFLM(x) Index: flang/test/Preprocessing/pp112.F90 =================================================================== --- flang/test/Preprocessing/pp112.F90 +++ flang/test/Preprocessing/pp112.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: res = iflm (666) ! ditto, but without & ! comment integer function IFLM(x) Index: flang/test/Preprocessing/pp113.F90 =================================================================== --- flang/test/Preprocessing/pp113.F90 +++ flang/test/Preprocessing/pp113.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: res = ((666)+111) ! FLM call split across continuation between name and (, leading & integer function IFLM(x) Index: flang/test/Preprocessing/pp114.F90 =================================================================== --- flang/test/Preprocessing/pp114.F90 +++ flang/test/Preprocessing/pp114.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: res = ((666)+111) ! ditto, with & ! comment, leading & integer function IFLM(x) Index: flang/test/Preprocessing/pp115.F90 =================================================================== --- flang/test/Preprocessing/pp115.F90 +++ flang/test/Preprocessing/pp115.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: res = iflm (666) ! ditto, with & ! comment, no leading & integer function IFLM(x) Index: flang/test/Preprocessing/pp116.F90 =================================================================== --- flang/test/Preprocessing/pp116.F90 +++ flang/test/Preprocessing/pp116.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: res = iflm (666) ! FLM call split between name and (, no leading & integer function IFLM(x) Index: flang/test/Preprocessing/pp117.F90 =================================================================== --- flang/test/Preprocessing/pp117.F90 +++ flang/test/Preprocessing/pp117.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(777 .eq. 777) then ! KWM rescan integer, parameter :: KWM = 666, KWM2 = 667 Index: flang/test/Preprocessing/pp118.F90 =================================================================== --- flang/test/Preprocessing/pp118.F90 +++ flang/test/Preprocessing/pp118.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(kwm2 .eq. 777) then ! KWM rescan with #undef, proving rescan after expansion integer, parameter :: KWM2 = 777, KWM = 667 Index: flang/test/Preprocessing/pp119.F90 =================================================================== --- flang/test/Preprocessing/pp119.F90 +++ flang/test/Preprocessing/pp119.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: res = ((666)+111) ! FLM rescan integer function IFLM(x) Index: flang/test/Preprocessing/pp120.F90 =================================================================== --- flang/test/Preprocessing/pp120.F90 +++ flang/test/Preprocessing/pp120.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: res = ((111)+666) ! FLM expansion of argument integer function IFLM(x) Index: flang/test/Preprocessing/pp121.F90 =================================================================== --- flang/test/Preprocessing/pp121.F90 +++ flang/test/Preprocessing/pp121.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: ch = 'KWM' ! CHECK: if(ch .eq. 'KWM') then ! KWM NOT expanded in 'literal' Index: flang/test/Preprocessing/pp122.F90 =================================================================== --- flang/test/Preprocessing/pp122.F90 +++ flang/test/Preprocessing/pp122.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: ch = "KWM" ! KWM NOT expanded in "literal" #define KWM 666 Index: flang/test/Preprocessing/pp123.F90 =================================================================== --- flang/test/Preprocessing/pp123.F90 +++ flang/test/Preprocessing/pp123.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: ch = 3hKWM ! KWM NOT expanded in Hollerith literal #define KWM 666 Index: flang/test/Preprocessing/pp124.F90 =================================================================== --- flang/test/Preprocessing/pp124.F90 +++ flang/test/Preprocessing/pp124.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: 100 format(3hKWM) ! KWM NOT expanded in Hollerith in FORMAT #define KWM 666 Index: flang/test/Preprocessing/pp125.F90 =================================================================== --- flang/test/Preprocessing/pp125.F90 +++ flang/test/Preprocessing/pp125.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(777 .eq. 777) then ! #DEFINE works in free form integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp126.F90 =================================================================== --- flang/test/Preprocessing/pp126.F90 +++ flang/test/Preprocessing/pp126.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(777 .eq. 777) then ! \ newline works in #define integer, parameter :: KWM = 666 Index: flang/test/Preprocessing/pp127.F90 =================================================================== --- flang/test/Preprocessing/pp127.F90 +++ flang/test/Preprocessing/pp127.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: res = iflm(666 ) ! FLM call with closing ')' on next line (not a continuation) integer function IFLM(x) Index: flang/test/Preprocessing/pp128.F90 =================================================================== --- flang/test/Preprocessing/pp128.F90 +++ flang/test/Preprocessing/pp128.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: res = iflm ! FLM call with '(' on next line (not a continuation) integer function IFLM(x) Index: flang/test/Preprocessing/pp129.F90 =================================================================== --- flang/test/Preprocessing/pp129.F90 +++ flang/test/Preprocessing/pp129.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-NOT: stop ! #define KWM !, then KWM works as comment line initiator #define KWM ! Index: flang/test/Preprocessing/pp130.F90 =================================================================== --- flang/test/Preprocessing/pp130.F90 +++ flang/test/Preprocessing/pp130.F90 @@ -1,4 +1,4 @@ -! RUN: not %flang -E %s 2>&1 | FileCheck %s +! RUN: not %flang -E -Xflang -fno-reformat %s 2>&1 | FileCheck %s ! CHECK: error: bad character ('&') in Fortran token ! #define KWM &, use for continuation w/o pasting (ifort and nag seem to continue #define) #define KWM & Index: flang/tools/f18-parse-demo/f18-parse-demo.cpp =================================================================== --- flang/tools/f18-parse-demo/f18-parse-demo.cpp +++ flang/tools/f18-parse-demo/f18-parse-demo.cpp @@ -87,9 +87,10 @@ 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 @@ 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 @@ 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 @@ 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); Index: flang/tools/f18/f18.cpp =================================================================== --- flang/tools/f18/f18.cpp +++ flang/tools/f18/f18.cpp @@ -93,9 +93,10 @@ 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 @@ 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 @@ 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 @@ } 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 @@ } 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, Index: flang/unittests/Frontend/FrontendActionTest.cpp =================================================================== --- flang/unittests/Frontend/FrontendActionTest.cpp +++ 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 @@ // Set-up the action kind. compInst_.invocation().frontendOpts().programAction_ = PrintPreprocessedInput; + compInst_.invocation().preprocessorOpts().set_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).