llvm-capstone/flang/test/Driver/include-header.f90
peter klausler 3338ef93b0 [flang] Produce proper "preprocessor output" for -E option
Rename the current -E option to "-E -Xflang -fno-reformat".

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

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

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

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

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

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

Differential Revision: https://reviews.llvm.org/D106727
2021-07-30 15:13:56 -07:00

73 lines
2.6 KiB
Fortran

! Ensure argument -I works as expected with an included header.
!--------------------------
! 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
!----------------------------------------
! 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
!--------------------------------------------
! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
!--------------------------------------------
! UNINCLUDED:#include: Source file 'basic-header-one.h' was not found
! UNINCLUDED-NOT:program b
! UNINCLUDED-NOT:program c
!---------------------------------------------
! EXPECTED OUTPUT FOR A SINGLE INCLUDED FOLDER
!--------------------------------------------
! SINGLEINCLUDE:program MainDirectoryOne
! SINGLEINCLUDE-NOT:program X
! SINGLEINCLUDE-NOT:program B
! SINGLEINCLUDE:program MainDirectoryTwo
! SINGLEINCLUDE-NOT:program Y
! SINGLEINCLUDE-NOT:program C
!-------------------------------------------------------
! EXPECTED OUTPUT FOR Inputs/ DIRECTORY SPECIFIED FIRST
!-------------------------------------------------------
! MAINDIRECTORY:program MainDirectoryOne
! MAINDIRECTORY-NOT:program SubDirectoryOne
! MAINDIRECTORY-NOT:program B
! MAINDIRECTORY:program MainDirectoryTwo
! MAINDIRECTORY-NOT:program SubDirectoryTwo
! MAINDIRECTORY-NOT:program C
!------------------------------------------------------------------
! EXPECTED OUTPUT FOR Inputs/header-dir/ DIRECTORY SPECIFIED FIRST
!------------------------------------------------------------------
! SUBDIRECTORY:program SubDirectoryOne
! SUBDIRECTORY-NOT:program MainDirectoryOne
! SUBDIRECTORY-NOT:program B
! SUBDIRECTORY:program SubDirectoryTwo
! SUBDIRECTORY-NOT:program MainDirectoryTwo
! SUBDIRECTORY-NOT:program C
! include-test-one.f90
#include <basic-header-one.h>
#ifdef X
program X
#else
program B
#endif
end
! include-test-two.f90
INCLUDE "basic-header-two.h"
#ifdef Y
program Y
#else
program C
#endif
end