llvm-capstone/flang/test/Driver/macro-def-undef.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

35 lines
1.1 KiB
Fortran

! Ensure arguments -D and -U work as expected.
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: %flang -E -P %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED
! RUN: %flang -E -P -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED
! RUN: %flang -E -P -DX=A -UX %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED
!-----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!-----------------------------------------
! RUN: %flang_fc1 -E -P %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED
! RUN: %flang_fc1 -E -P -DX=A %s 2>&1 | FileCheck %s --check-prefix=DEFINED
! RUN: %flang_fc1 -E -P -DX -UX %s 2>&1 | FileCheck %s --check-prefix=UNDEFINED
!--------------------------------------------
! EXPECTED OUTPUT FOR AN UNDEFINED MACRO
!--------------------------------------------
! UNDEFINED:program B
! UNDEFINED-NOT:program X
!--------------------------------------------
! EXPECTED OUTPUT FOR MACRO 'X' DEFINED AS A
!--------------------------------------------
! DEFINED:program A
! DEFINED-NOT:program B
#ifdef X
program X
#else
program B
#endif
end