llvm-project/flang/test/Driver/save-temps.f90
Andrzej Warzynski a65afce731 [flang][driver] Add support for -save-temps
This patch adds support for `-save-temps` in `flang-new`, Flang's
compiler driver. The semantics of this option are inherited from Clang.

The file extension for temporary Fortran preprocessed files is set to
`i`. This is identical to what Clang uses for C (or C++) preprocessed
files. I have tried researching what other compilers do here, but I
couldn't find any definitive answers. One GFortran thread [1] suggests
that indeed it is not clear what the right approach should be.

Normally, various phases in Clang/Flang are combined. The `-save-temps`
option works by forcing the compiler to run every phase separately. As
there is no integrated assembler driver in Flang, user will have to use
`-save-temps` together with `-fno-integrated-as`. Otherwise, an
invocation to the integrated assembler would be generated generated,
which is going to fail (i.e. something equivalent to `clang -cc1as` from
Clang).

There are no specific plans for implementing an integrated assembler for
Flang for now. One possible solution would be to share it entirely with
Clang.

Note that on Windows you will get the following error when using
`-fno-integrated-as`:
```bash
  flang-new: error: there is no external assembler that can be used on this platform
```
Unfortunately, I don't have access to a Windows machine to investigate
this. Instead, I marked the tests in this patch as unsupported on
Windows.

[1] https://gcc.gnu.org/bugzilla//show_bug.cgi?id=81615

Differential Revision: https://reviews.llvm.org/D124669
2022-05-06 08:41:29 +00:00

56 lines
2.0 KiB
Fortran

! Tests for the `-save-temps` flag. As `flang` does not implement `-fc1as` (i.e. a driver for the integrated assembler), we need to
! use `-fno-integrated-as` here.
! UNSUPPORTED: system-windows
!--------------------------
! Basic case: `-save-temps`
!--------------------------
! RUN: %flang -save-temps -fno-integrated-as %s -### 2>&1 | FileCheck %s
! CHECK: "-o" "save-temps.i"
! CHECK-NEXT: "-o" "save-temps.bc"
! CHECK-NEXT: "-o" "save-temps.s"
! CHECK-NEXT: "-o" "save-temps.o"
! CHECK-NEXT: "-o" "a.out"
!--------------------------
! `-save-temps=cwd`
!--------------------------
! This should work the same as -save-temps above
! RUN: %flang -save-temps=cwd -fno-integrated-as %s -### 2>&1 | FileCheck %s -check-prefix=CWD
! CWD: "-o" "save-temps.i"
! CWD-NEXT: "-o" "save-temps.bc"
! CWD-NEXT: "-o" "save-temps.s"
! CWD-NEXT: "-o" "save-temps.o"
! CWD-NEXT: "-o" "a.out"
!--------------------------
! `-save-temps=obj`
!--------------------------
! Check that temp files are saved in the same directory as the output file
! regardless of whether -o is specified.
! RUN: %flang -save-temps=obj -fno-integrated-as -o obj/dir/a.out %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ
! CHECK-OBJ: "-o" "obj/dir/save-temps.i"
! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.bc"
! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.s"
! CHECK-OBJ-NEXT: "-o" "obj/dir/save-temps.o"
! CHECK-OBJ-NEXT: "-o" "obj/dir/a.out"
! RUN: %flang -save-temps=obj -fno-integrated-as %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OBJ-NOO
! CHECK-OBJ-NOO: "-o" "save-temps.i"
! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.bc"
! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.s"
! CHECK-OBJ-NOO-NEXT: "-o" "save-temps.o"
! CHECK-OBJ-NOO-NEXT: "-o" "a.out"
!--------------------------
! `-S` without `-save-temps`
!--------------------------
! Check for a single `flang -fc1` invocation when NOT using -save-temps.
! RUN: %flang -S %s -### 2>&1 | FileCheck %s -check-prefix=NO-TEMPS
! NO-TEMPS: "-fc1"
! NO-TEMPS-SAME: "-S"
! NO-TEMPS-SAME: "-o" "save-temps.s"