llvm-project/flang/test/Driver/fixed-free-detection.f90

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
1.8 KiB
Fortran
Raw Normal View History

[flang][driver] Add support for fixed form detection Currently the new flang driver always runs in free form mode. This patch adds support for fixed form mode detection based on the file extensions. Like `f18`, `flang-new` will treat files ending with ".f", ".F" and ".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP" file extensions are recognised as fixed form files. This is consistent with gfortran [1]. In summary, files with the following extensions are treated as fixed-form: * ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP" For consistency with flang/test/lit.cfg.py and f18, this patch also adds support for the following file extensions: * ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP" This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally, the following extensions are included: * ".f03", ".F03", ".f08", ".F08" This is for compatibility with gfortran [1] and other popular Fortran compilers [2]. NOTE: internally Flang will only differentiate between fixed and free form files. Currently Flang does not support switching between language standards, so in this regard file extensions are irrelevant. More specifically, both `file.f03` and `file.f18` are represented with `Language::Fortran` (as opposed to e.g. `Language::Fortran03`). Summary of changes: - Set Fortran::parser::Options::sFixedForm according to the file type - Add isFixedFormSuffix and isFreeFormSuffix helper functions to FrontendTool/Utils.h - Change FrontendOptions::GetInputKindForExtension to support the missing file extensions that f18 supports and some additional ones - FrontendActionTest.cpp is updated to make sure that the test input is treated as free-form [1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html [2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes Differential Revision: https://reviews.llvm.org/D94228
2021-01-05 00:49:33 +08:00
! Ensure the driver correctly switches between fixed and free form based on the file extension.
! This test exploits the fact that the preprocessor treats white-spaces differently for free
! and fixed form input files.
! REQUIRES: new-flang-driver
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: %flang-new -E %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREEFORM
! RUN: %flang-new -E %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXEDFORM
! RUN: %flang-new -E %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=MULTIPLEFORMS
!-----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!-----------------------------------------
! RUN: %flang-new -fc1 -E %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREEFORM
! RUN: %flang-new -fc1 -E %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXEDFORM
! RUN: %flang-new -fc1 -E %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
!-------------------------------------
! FREEFORM:program freeform
! FREEFORM-NOT:programfixedform
!---------------------------------------
! EXPECTED OUTPUT FOR A FIXED FORM FILE
!---------------------------------------
! FIXEDFORM:programfixedform
! FIXEDFORM-NOT:program freeform
!------------------------------------------------
! EXPECTED OUTPUT FOR 2 FILES OF DIFFERENT FORMS
!------------------------------------------------
! MULTIPLEFORMS:program freeform
! MULTIPLEFORMS-NOT:programfixedform
! MULTIPLEFORMS-NEXT:end
! MULTIPLEFORMS-NEXT:programfixedform
! MULTIPLEFORMS-NOT:program freeform