-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
988748c
commit a65afce
Showing
6 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
! Tests for the `-fno-integrated-as` flag. | ||
|
||
! UNSUPPORTED: system-windows | ||
|
||
!-------------------------- | ||
! With `-fno-integrated-as` | ||
!-------------------------- | ||
! Verify that there _is_ a separate line with an assembler invocation | ||
! RUN: %flang -c -fno-integrated-as %s -### 2>&1 | FileCheck %s | ||
! CHECK-LABEL: "-fc1" | ||
! CHECK-SAME: "-o" "[[assembly_file:.*]].s" | ||
! CHECK-NEXT: "-o" "{{.*}}.o" "[[assembly_file:.*]].s" | ||
|
||
!----------------------------- | ||
! Without `-fno-integrated-as` | ||
!----------------------------- | ||
! Verify that there _is no_ separate line with an assembler invocation | ||
! RUN: %flang -c %s -### 2>&1 | FileCheck %s -check-prefix=DEFAULT | ||
! DEFAULT-LABEL: "-fc1" | ||
! DEFAULT-SAME: "-o" "{{.*}}.o" "{{.*}}fno-integrated-as.f90" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
! 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" |