[clang] b83a445 - [flang][driver] Add support for `-cpp/-nocpp`

Andrzej Warzynski via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 06:02:05 PDT 2021


Author: Andrzej Warzynski
Date: 2021-04-07T13:01:52Z
New Revision: b83a4450c216879d76d78c21a2a0b864fdc2eb3d

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

LOG: [flang][driver] Add support for `-cpp/-nocpp`

This patch adds support for the `-cpp` and `-nocpp` flags. The
implemented semantics match f18 (i.e. the "throwaway" driver), but are
different to gfortran. In Flang the preprocessor is always run. Instead,
`-cpp/-nocpp` are used to control whether predefined and command-line
preprocessor macro definitions are enabled or not. In practice this is
sufficient to model gfortran`s `-cpp/-nocpp`.

In the absence of `-cpp/-nocpp`, the driver will use the extension of
the input file to decide whether to include the standard macro
predefinitions. gfortran's documentation [1] was used to decide which
file extension to use for this.

The logic mentioned above was added in FrontendAction::BeginSourceFile.
That's relatively late in the driver set-up, but this roughly where the
name of the input file becomes available. The logic for deciding between
fixed and free form works in a similar way and was also moved to
FrontendAction::BeginSourceFile for consistency (and to reduce
code-duplication).

The `-cpp/-nocpp` flags are respected also when the input is read from
stdin. This is different to:
   * gfortran (behaves as if `-cpp` was used)
   * f18 (behaves as if `-nocpp` was used)

Starting with this patch, file extensions are significant and some test
files had to be renamed to reflect that. Where possible, preprocessor
tests were updated so that they can be shared between `f18` and
`flang-new`. This was implemented on top of adding new test for
`-cpp/-nocpp`.

[1] https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html

Reviewed By: kiranchandramohan

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

Added: 
    flang/test/Driver/cpp-nocpp-command-line-macro.f90
    flang/test/Driver/cpp-nocpp-predefined-macro.F90
    flang/test/Driver/macro-def-undef.F90
    flang/test/Driver/macro-multiline.F90
    flang/test/Driver/predefined-macros-compiler-version.F90

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Flang.cpp
    flang/include/flang/Frontend/CompilerInvocation.h
    flang/include/flang/Frontend/FrontendOptions.h
    flang/include/flang/Frontend/PreprocessorOptions.h
    flang/lib/Frontend/CompilerInstance.cpp
    flang/lib/Frontend/CompilerInvocation.cpp
    flang/lib/Frontend/FrontendAction.cpp
    flang/lib/Frontend/FrontendActions.cpp
    flang/lib/Frontend/FrontendOptions.cpp
    flang/test/Driver/driver-help-hidden.f90
    flang/test/Driver/driver-help.f90
    flang/test/Driver/input-from-stdin.f90

Removed: 
    flang/test/Driver/macro-def-undef.f90
    flang/test/Driver/macro-multiline.f90
    flang/test/Driver/predefined-macros-compiler-version.f90


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1a71d68ec4e2..240656a6e519 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4235,8 +4235,6 @@ defm devirtualize_speculatively : BooleanFFlag<"devirtualize-speculatively">,
 
 // Generic gfortran options.
 def A_DASH : Joined<["-"], "A-">, Group<gfortran_Group>;
-def cpp : Flag<["-"], "cpp">, Group<gfortran_Group>;
-def nocpp : Flag<["-"], "nocpp">, Group<gfortran_Group>;
 def static_libgfortran : Flag<["-"], "static-libgfortran">, Group<gfortran_Group>;
 
 // "f" options with values for gfortran.
@@ -4316,6 +4314,10 @@ def Xflang : Separate<["-"], "Xflang">,
 //===----------------------------------------------------------------------===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
+def cpp : Flag<["-"], "cpp">, Group<f_Group>,
+  HelpText<"Enable predefined and command line preprocessor macros">;
+def nocpp : Flag<["-"], "nocpp">, Group<f_Group>,
+  HelpText<"Disable predefined and command line preprocessor macros">;
 def module_dir : Separate<["-"], "module-dir">, MetaVarName<"<dir>">,
   HelpText<"Put MODULE files in <dir>">,
   DocBrief<[{This option specifies where to put .mod files for compiled modules.

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 73dbeacf2563..1bfad6115d51 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -37,7 +37,8 @@ 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});
+  Args.AddAllArgs(CmdArgs, {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/CompilerInvocation.h b/flang/include/flang/Frontend/CompilerInvocation.h
index 529f15e3c886..edd32917b175 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -143,6 +143,10 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// Set the default predefinitions.
   void setDefaultPredefinitions();
 
+  /// Collect the macro definitions from preprocessorOpts_ and prepare them for
+  /// the parser (i.e. copy into parserOpts_)
+  void collectMacroDefinitions();
+
   /// Set the Fortran options to user-specified values.
   /// These values are found in the preprocessor options.
   void setFortranOpts();

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h
index 1d9002335c3c..4e5fa0a476af 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -79,6 +79,10 @@ Fortran::parser::AnalyzedObjectsAsFortran getBasicAsFortran();
 /// \return True if the file extension should be processed as free form
 bool isFreeFormSuffix(llvm::StringRef suffix);
 
+/// \param suffix The file extension
+/// \return True if the file should be preprocessed
+bool mustBePreprocessed(llvm::StringRef suffix);
+
 enum class Language : uint8_t {
   Unknown,
 
@@ -137,6 +141,12 @@ class FrontendInputFile {
   /// stdin this is never modified.
   bool isFixedForm_ = false;
 
+  /// Must this file be preprocessed? Note that in Flang the preprocessor is
+  /// always run. This flag is used to control whether predefined and command
+  /// line preprocessor macros are enabled or not. In practice, this is
+  /// sufficient to implement gfortran`s logic controlled with `-cpp/-nocpp`.
+  unsigned mustBePreprocessed_ : 1;
+
 public:
   FrontendInputFile() = default;
   FrontendInputFile(llvm::StringRef file, InputKind kind)
@@ -147,7 +157,9 @@ class FrontendInputFile {
     auto pathDotIndex{file.rfind(".")};
     std::string pathSuffix{file.substr(pathDotIndex + 1)};
     isFixedForm_ = isFixedFormSuffix(pathSuffix);
+    mustBePreprocessed_ = mustBePreprocessed(pathSuffix);
   }
+
   FrontendInputFile(const llvm::MemoryBuffer *buffer, InputKind kind)
       : buffer_(buffer), kind_(kind) {}
 
@@ -157,6 +169,7 @@ class FrontendInputFile {
   bool IsFile() const { return !IsBuffer(); }
   bool IsBuffer() const { return buffer_ != nullptr; }
   bool IsFixedForm() const { return isFixedForm_; }
+  bool MustBePreprocessed() const { return mustBePreprocessed_; }
 
   llvm::StringRef file() const {
     assert(IsFile());

diff  --git a/flang/include/flang/Frontend/PreprocessorOptions.h b/flang/include/flang/Frontend/PreprocessorOptions.h
index 3a3877bf0b28..1e833194ac35 100644
--- a/flang/include/flang/Frontend/PreprocessorOptions.h
+++ b/flang/include/flang/Frontend/PreprocessorOptions.h
@@ -19,6 +19,16 @@
 
 namespace Fortran::frontend {
 
+/// Communicates whether to include/exclude predefined and command
+/// line preprocessor macros
+enum class PPMacrosFlag : uint8_t {
+  /// Use the file extension to decide
+  Unknown,
+
+  Include,
+  Exclude
+};
+
 /// This class is used for passing the various options used
 /// in preprocessor initialization to the parser options.
 class PreprocessorOptions {
@@ -32,6 +42,8 @@ class PreprocessorOptions {
   // Search directories specified by the user with -fintrinsic-modules-path
   std::vector<std::string> searchDirectoriesFromIntrModPath;
 
+  PPMacrosFlag macrosFlag_ = PPMacrosFlag::Unknown;
+
 public:
   PreprocessorOptions() {}
 

diff  --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index 01eaed32ed9f..c3e538911d41 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -142,7 +142,6 @@ bool CompilerInstance::ExecuteAction(FrontendAction &act) {
 
   // Set some sane defaults for the frontend.
   invoc.SetDefaultFortranOpts();
-  invoc.setDefaultPredefinitions();
   // Update the fortran options based on user-based input.
   invoc.setFortranOpts();
   // Set the encoding to read all input files in based on user input.

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index ce7392cf3d76..6c6277c5a56a 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -323,6 +323,14 @@ static void parsePreprocessorArgs(
   for (const auto *currentArg :
       args.filtered(clang::driver::options::OPT_fintrinsic_modules_path))
     opts.searchDirectoriesFromIntrModPath.emplace_back(currentArg->getValue());
+
+  // -cpp/-nocpp
+  if (const auto *currentArg = args.getLastArg(
+          clang::driver::options::OPT_cpp, clang::driver::options::OPT_nocpp))
+    opts.macrosFlag_ =
+        (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
+        ? PPMacrosFlag::Include
+        : PPMacrosFlag::Exclude;
 }
 
 /// Parses all semantic related arguments and populates the variables
@@ -471,13 +479,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
   return success;
 }
 
-/// Collect the macro definitions provided by the given preprocessor
-/// options into the parser options.
-///
-/// \param [in] ppOpts The preprocessor options
-/// \param [out] opts The fortran options
-static void collectMacroDefinitions(
-    const PreprocessorOptions &ppOpts, Fortran::parser::Options &opts) {
+void CompilerInvocation::collectMacroDefinitions() {
+  auto &ppOpts = this->preprocessorOpts();
+
   for (unsigned i = 0, n = ppOpts.macros.size(); i != n; ++i) {
     llvm::StringRef macro = ppOpts.macros[i].first;
     bool isUndef = ppOpts.macros[i].second;
@@ -488,7 +492,7 @@ static void collectMacroDefinitions(
 
     // For an #undef'd macro, we only care about the name.
     if (isUndef) {
-      opts.predefinitions.emplace_back(
+      parserOpts_.predefinitions.emplace_back(
           macroName.str(), std::optional<std::string>{});
       continue;
     }
@@ -501,7 +505,7 @@ static void collectMacroDefinitions(
       llvm::StringRef::size_type End = macroBody.find_first_of("\n\r");
       macroBody = macroBody.substr(0, End);
     }
-    opts.predefinitions.emplace_back(
+    parserOpts_.predefinitions.emplace_back(
         macroName, std::optional<std::string>(macroBody.str()));
   }
 }
@@ -557,8 +561,6 @@ void CompilerInvocation::setFortranOpts() {
   fortranOptions.features = frontendOptions.features_;
   fortranOptions.encoding = frontendOptions.encoding_;
 
-  collectMacroDefinitions(preprocessorOptions, fortranOptions);
-
   // Adding search directories specified by -I
   fortranOptions.searchDirectories.insert(
       fortranOptions.searchDirectories.end(),

diff  --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index 650fd2999bed..23e4ca3f3306 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -67,6 +67,25 @@ bool FrontendAction::BeginSourceFile(
     return false;
   }
 
+  auto &invoc = ci.invocation();
+
+  // Include command-line and predefined preprocessor macros. Use either:
+  //  * `-cpp/-nocpp`, or
+  //  * the file extension (if the user didn't express any preference)
+  // to decide whether to include them or not.
+  if ((invoc.preprocessorOpts().macrosFlag_ == PPMacrosFlag::Include) ||
+      (invoc.preprocessorOpts().macrosFlag_ == PPMacrosFlag::Unknown &&
+          currentInput().MustBePreprocessed())) {
+    invoc.setDefaultPredefinitions();
+    invoc.collectMacroDefinitions();
+  }
+
+  // Decide between fixed and free form (if the user didn't express any
+  // preference, use the file extension to decide)
+  if (invoc.frontendOpts().fortranForm_ == FortranForm::Unknown) {
+    invoc.fortranOpts().isFixedForm = currentInput().IsFixedForm();
+  }
+
   if (!BeginSourceFileAction(ci)) {
     BeginSourceFileCleanUp(*this, ci);
     return false;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index f5420c281f8a..6aa7e2602ea6 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -10,6 +10,7 @@
 #include "flang/Common/default-kinds.h"
 #include "flang/Frontend/CompilerInstance.h"
 #include "flang/Frontend/FrontendOptions.h"
+#include "flang/Frontend/PreprocessorOptions.h"
 #include "flang/Lower/PFTBuilder.h"
 #include "flang/Parser/dump-parse-tree.h"
 #include "flang/Parser/parsing.h"
@@ -45,21 +46,9 @@ bool reportFatalSemanticErrors(const Fortran::semantics::Semantics &semantics,
 
 bool PrescanAction::BeginSourceFileAction(CompilerInstance &c1) {
   CompilerInstance &ci = this->instance();
-
   std::string currentInputPath{GetCurrentFileOrBufferName()};
-
   Fortran::parser::Options parserOptions = ci.invocation().fortranOpts();
 
-  if (ci.invocation().frontendOpts().fortranForm_ == FortranForm::Unknown) {
-    // Switch between fixed and free form format based on the input file
-    // extension.
-    //
-    // Ideally we should have all Fortran options set before entering this
-    // method (i.e. before processing any specific input files). However, we
-    // can't decide between fixed and free form based on the file extension
-    // earlier than this.
-    parserOptions.isFixedForm = currentInput().IsFixedForm();
-  }
 
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
@@ -80,22 +69,9 @@ bool PrescanAction::BeginSourceFileAction(CompilerInstance &c1) {
 
 bool PrescanAndSemaAction::BeginSourceFileAction(CompilerInstance &c1) {
   CompilerInstance &ci = this->instance();
-
   std::string currentInputPath{GetCurrentFileOrBufferName()};
-
   Fortran::parser::Options parserOptions = ci.invocation().fortranOpts();
 
-  if (ci.invocation().frontendOpts().fortranForm_ == FortranForm::Unknown) {
-    // Switch between fixed and free form format based on the input file
-    // extension.
-    //
-    // Ideally we should have all Fortran options set before entering this
-    // method (i.e. before processing any specific input files). However, we
-    // can't decide between fixed and free form based on the file extension
-    // earlier than this.
-    parserOptions.isFixedForm = currentInput().IsFixedForm();
-  }
-
   // Prescan. In case of failure, report and return.
   ci.parsing().Prescan(currentInputPath, parserOptions);
 

diff  --git a/flang/lib/Frontend/FrontendOptions.cpp b/flang/lib/Frontend/FrontendOptions.cpp
index 2c2f7b84230c..94fff8799177 100644
--- a/flang/lib/Frontend/FrontendOptions.cpp
+++ b/flang/lib/Frontend/FrontendOptions.cpp
@@ -26,6 +26,12 @@ bool Fortran::frontend::isFreeFormSuffix(llvm::StringRef suffix) {
       suffix == "F08" || suffix == "f18" || suffix == "F18";
 }
 
+bool Fortran::frontend::mustBePreprocessed(llvm::StringRef suffix) {
+  return suffix == "F" || suffix == "FOR" || suffix == "fpp" ||
+      suffix == "FPP" || suffix == "F90" || suffix == "F95" ||
+      suffix == "F03" || suffix == "F08" || suffix == "F18";
+}
+
 // TODO: This is a copy of `asFortran` from f18.cpp and is added here for
 // compatiblity. It doesn't really belong here, but I couldn't find a better
 // place. We should decide whether to add it to the Evaluate or Parse/Unparse

diff  --git a/flang/test/Driver/cpp-nocpp-command-line-macro.f90 b/flang/test/Driver/cpp-nocpp-command-line-macro.f90
new file mode 100644
index 000000000000..1aacde0f308f
--- /dev/null
+++ b/flang/test/Driver/cpp-nocpp-command-line-macro.f90
@@ -0,0 +1,22 @@
+!-----------
+! 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
+
+!-----------------
+! EXPECTED OUTPUT
+!-----------------
+! UNDEFINED:program b
+! UNDEFINED-NOT:program a
+
+! DEFINED:program a
+! DEFINED-NOT:program b
+
+#ifdef X
+program X
+#else
+program B
+#endif
+end

diff  --git a/flang/test/Driver/cpp-nocpp-predefined-macro.F90 b/flang/test/Driver/cpp-nocpp-predefined-macro.F90
new file mode 100644
index 000000000000..77bb38c8174c
--- /dev/null
+++ b/flang/test/Driver/cpp-nocpp-predefined-macro.F90
@@ -0,0 +1,18 @@
+!-----------
+! RUN lines
+!-----------
+! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang_fc1 -E -cpp %s 2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang_fc1 -E -nocpp %s 2>&1 | FileCheck %s --check-prefix=NOT_DEFINED
+
+!-----------------
+! EXPECTED OUTPUT
+!-----------------
+! DEFINED: flang = 1
+! DEFINED-NEXT: flang_major = {{[1-9][0-9]*$}}
+
+! NOT_DEFINED: flang = __flang__
+! NOT_DEFINED-NEXT: flang_major = __flang_major__
+
+integer, parameter :: flang = __flang__
+integer, parameter :: flang_major = __flang_major__

diff  --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index 263dfb10de0b..164b6d104ebc 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -19,6 +19,7 @@
 ! CHECK-EMPTY:
 ! CHECK-NEXT:OPTIONS:
 ! CHECK-NEXT: -###      Print (but do not run) the commands to run for this compilation
+! CHECK-NEXT: -cpp      Enable predefined and command line preprocessor macros
 ! CHECK-NEXT: -c        Only run preprocess, compile, and assemble steps
 ! CHECK-NEXT: -D <macro>=<value>     Define <macro> to <value> (or 1 if <value> omitted)
 ! CHECK-NEXT: -E        Only run the preprocessor
@@ -46,6 +47,7 @@
 ! CHECK-NEXT: -help     Display available options
 ! CHECK-NEXT: -I <dir>               Add directory to the end of the list of include search paths
 ! CHECK-NEXT: -module-dir <dir>      Put MODULE files in <dir>
+! 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: -std=<value>           Language standard to compile for

diff  --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90
index ba755efeb280..ed4648cfa48a 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -19,6 +19,7 @@
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
 ! HELP-NEXT: -###                   Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -cpp                   Enable predefined and command line preprocessor macros
 ! HELP-NEXT: -c                     Only run preprocess, compile, and assemble steps
 ! HELP-NEXT: -D <macro>=<value>     Define <macro> to <value> (or 1 if <value> omitted)
 ! HELP-NEXT: -E                     Only run the preprocessor
@@ -46,6 +47,7 @@
 ! HELP-NEXT: -help                  Display available options
 ! HELP-NEXT: -I <dir>               Add directory to the end of the list of include search paths
 ! HELP-NEXT: -module-dir <dir>      Put MODULE files in <dir>
+! 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: -std=<value>           Language standard to compile for
@@ -60,6 +62,7 @@
 ! HELP-FC1:USAGE: flang-new
 ! HELP-FC1-EMPTY:
 ! HELP-FC1-NEXT:OPTIONS:
+! HELP-FC1-NEXT: -cpp                   Enable predefined and command line preprocessor macros
 ! HELP-FC1-NEXT: -D <macro>=<value>     Define <macro> to <value> (or 1 if <value> omitted)
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E                     Only run the preprocessor
@@ -98,6 +101,7 @@
 ! HELP-FC1-NEXT: -help                  Display available options
 ! HELP-FC1-NEXT: -I <dir>               Add directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -module-dir <dir>      Put MODULE files in <dir>
+! 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: -std=<value>           Language standard to compile for

diff  --git a/flang/test/Driver/input-from-stdin.f90 b/flang/test/Driver/input-from-stdin.f90
index 606cc41520fe..4f14e37a8360 100644
--- a/flang/test/Driver/input-from-stdin.f90
+++ b/flang/test/Driver/input-from-stdin.f90
@@ -6,24 +6,26 @@
 ! FLANG DRIVER (flang)
 !--------------------------
 ! Input type is implicit
-! RUN: cat %s | %flang -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED
-! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED
+! 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
 
 ! Input type is explicit
-! RUN: cat %s | %flang -E -x f95-cpp-input - | FileCheck %s --check-prefix=PP-NOT-DEFINED
-! RUN: cat %s | %flang -DNEW -E -x f95-cpp-input - | FileCheck %s --check-prefix=PP-DEFINED
+! 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
 
 !---------------------------------------
 ! 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 | FileCheck %s --check-prefix=PP-NOT-DEFINED
-! RUN: cat %s | %flang -fc1 -DNEW -E | FileCheck %s --check-prefix=PP-DEFINED
+! 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
 
 ! Test `-test-io`: for the corresponding frontend action (`InputOutputTestAction`) the driver handles the file I/O on its own
 ! the corresponding action (`PrintPreprocessedAction`)
-! RUN: cat %s | %flang -fc1 -test-io | FileCheck %s --check-prefix=IO --match-full-lines
-! RUN: cat %s | %flang -fc1 -DNEW -test-io | FileCheck %s --check-prefix=IO --match-full-lines
+! RUN: cat %s | %flang -fc1 -test-io -cpp | FileCheck %s --check-prefix=IO --match-full-lines
+! RUN: cat %s | %flang -fc1 -DNEW -cpp -test-io | FileCheck %s --check-prefix=IO --match-full-lines
 
 !-------------------------
 ! EXPECTED OUTPUT for `-E`

diff  --git a/flang/test/Driver/macro-def-undef.f90 b/flang/test/Driver/macro-def-undef.F90
similarity index 60%
rename from flang/test/Driver/macro-def-undef.f90
rename to flang/test/Driver/macro-def-undef.F90
index 694f7676eeb1..b2310fae0dc1 100644
--- a/flang/test/Driver/macro-def-undef.f90
+++ b/flang/test/Driver/macro-def-undef.F90
@@ -1,20 +1,18 @@
 ! Ensure arguments -D and -U work as expected.
 
-! REQUIRES: new-flang-driver
-
 !--------------------------
 ! FLANG DRIVER (flang-new)
 !--------------------------
-! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
-! RUN: %flang-new -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
-! RUN: %flang-new -E -DX=A -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! 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
 
 !-----------------------------------------
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-----------------------------------------
-! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
-! RUN: %flang-new -fc1 -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
-! RUN: %flang-new -fc1 -E -DX -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! 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
 
 !--------------------------------------------
 ! EXPECTED OUTPUT FOR AN UNDEFINED MACRO
@@ -35,4 +33,4 @@ program X
 #else
 program B
 #endif
-end
\ No newline at end of file
+end

diff  --git a/flang/test/Driver/macro-multiline.f90 b/flang/test/Driver/macro-multiline.F90
similarity index 100%
rename from flang/test/Driver/macro-multiline.f90
rename to flang/test/Driver/macro-multiline.F90

diff  --git a/flang/test/Driver/predefined-macros-compiler-version.f90 b/flang/test/Driver/predefined-macros-compiler-version.F90
similarity index 81%
rename from flang/test/Driver/predefined-macros-compiler-version.f90
rename to flang/test/Driver/predefined-macros-compiler-version.F90
index bf59f305e884..e395b1a58078 100644
--- a/flang/test/Driver/predefined-macros-compiler-version.f90
+++ b/flang/test/Driver/predefined-macros-compiler-version.F90
@@ -1,16 +1,14 @@
 ! Check that the driver correctly defines macros with the compiler version
 
-! REQUIRES: new-flang-driver
-
 !--------------------------
 ! FLANG DRIVER (flang-new)
 !--------------------------
-! RUN: %flang-new -E %s  2>&1 | FileCheck %s --ignore-case
+! RUN: %flang_fc1 -E %s  2>&1 | FileCheck %s --ignore-case
 
 !-----------------------------------------
 ! FRONTEND FLANG DRIVER (flang-new -fc1)
 !-----------------------------------------
-! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --ignore-case
+! RUN: %flang_fc1 -E %s  2>&1 | FileCheck %s --ignore-case
 
 !-----------------
 ! EXPECTED OUTPUT


        


More information about the cfe-commits mailing list