[all-commits] [llvm/llvm-project] b83a44: [flang][driver] Add support for `-cpp/-nocpp`

Andrzej WarzyƄski via All-commits all-commits at lists.llvm.org
Wed Apr 7 06:02:23 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b83a4450c216879d76d78c21a2a0b864fdc2eb3d
      https://github.com/llvm/llvm-project/commit/b83a4450c216879d76d78c21a2a0b864fdc2eb3d
  Author: Andrzej Warzynski <andrzej.warzynski at arm.com>
  Date:   2021-04-07 (Wed, 07 Apr 2021)

  Changed paths:
    M clang/include/clang/Driver/Options.td
    M clang/lib/Driver/ToolChains/Flang.cpp
    M flang/include/flang/Frontend/CompilerInvocation.h
    M flang/include/flang/Frontend/FrontendOptions.h
    M flang/include/flang/Frontend/PreprocessorOptions.h
    M flang/lib/Frontend/CompilerInstance.cpp
    M flang/lib/Frontend/CompilerInvocation.cpp
    M flang/lib/Frontend/FrontendAction.cpp
    M flang/lib/Frontend/FrontendActions.cpp
    M flang/lib/Frontend/FrontendOptions.cpp
    A flang/test/Driver/cpp-nocpp-command-line-macro.f90
    A flang/test/Driver/cpp-nocpp-predefined-macro.F90
    M flang/test/Driver/driver-help-hidden.f90
    M flang/test/Driver/driver-help.f90
    M flang/test/Driver/input-from-stdin.f90
    A flang/test/Driver/macro-def-undef.F90
    R flang/test/Driver/macro-def-undef.f90
    A flang/test/Driver/macro-multiline.F90
    R flang/test/Driver/macro-multiline.f90
    A flang/test/Driver/predefined-macros-compiler-version.F90
    R flang/test/Driver/predefined-macros-compiler-version.f90

  Log Message:
  -----------
  [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




More information about the All-commits mailing list