diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3995,9 +3995,9 @@ NegFlag>; def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>, Group; -def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, NoXarchOption]>, +def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, FlangOption, NoXarchOption]>, HelpText<"Save intermediate compilation results.">; -def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>, +def save_temps : Flag<["-", "--"], "save-temps">, Flags<[FlangOption, NoXarchOption]>, Alias, AliasArgs<["cwd"]>, HelpText<"Save intermediate compilation results">; def save_stats_EQ : Joined<["-", "--"], "save-stats=">, Flags<[NoXarchOption]>, @@ -4125,7 +4125,7 @@ defm integrated_as : BoolFOption<"integrated-as", CodeGenOpts<"DisableIntegratedAS">, DefaultFalse, - NegFlag, PosFlag, + NegFlag, PosFlag, BothFlags<[], " the integrated assembler">>; def fintegrated_cc1 : Flag<["-"], "fintegrated-cc1">, @@ -4137,7 +4137,7 @@ def : Flag<["-"], "integrated-as">, Alias, Flags<[NoXarchOption]>; def : Flag<["-"], "no-integrated-as">, Alias, - Flags<[CC1Option, NoXarchOption]>; + Flags<[CC1Option, FlangOption, NoXarchOption]>; def working_directory : JoinedOrSeparate<["-"], "working-directory">, Flags<[CC1Option]>, HelpText<"Resolve file paths relative to the specified directory">, diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def --- a/clang/include/clang/Driver/Types.def +++ b/clang/include/clang/Driver/Types.def @@ -77,7 +77,7 @@ TYPE("ada", Ada, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("assembler", PP_Asm, INVALID, "s", phases::Assemble, phases::Link) TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases::Preprocess, phases::Assemble, phases::Link) -TYPE("f95", PP_Fortran, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link) +TYPE("f95", PP_Fortran, INVALID, "i", phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link) TYPE("java", Java, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link) diff --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90 --- a/flang/test/Driver/driver-help-hidden.f90 +++ b/flang/test/Driver/driver-help-hidden.f90 @@ -44,6 +44,7 @@ ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler ! CHECK-NEXT: -fopenacc Enable OpenACC ! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -58,6 +59,8 @@ ! CHECK-NEXT: -print-effective-triple Print the effective target triple ! CHECK-NEXT: -print-target-triple Print the normalized target triple ! CHECK-NEXT: -P Disable linemarker output in -E mode +! CHECK-NEXT: -save-temps= Save intermediate compilation results. +! CHECK-NEXT: -save-temps Save intermediate compilation results ! CHECK-NEXT: -std= Language standard to compile for ! CHECK-NEXT: -S Only run preprocess and compilation steps ! CHECK-NEXT: --target= Generate code for the given target diff --git a/flang/test/Driver/driver-help.f90 b/flang/test/Driver/driver-help.f90 --- a/flang/test/Driver/driver-help.f90 +++ b/flang/test/Driver/driver-help.f90 @@ -42,6 +42,7 @@ ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics +! HELP-NEXT: -fno-integrated-as Disable the integrated assembler ! HELP-NEXT: -fopenacc Enable OpenACC ! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code. ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV. @@ -56,6 +57,8 @@ ! HELP-NEXT: -print-effective-triple Print the effective target triple ! HELP-NEXT: -print-target-triple Print the normalized target triple ! HELP-NEXT: -P Disable linemarker output in -E mode +! HELP-NEXT: -save-temps= Save intermediate compilation results. +! HELP-NEXT: -save-temps Save intermediate compilation results ! HELP-NEXT: -std= Language standard to compile for ! HELP-NEXT: -S Only run preprocess and compilation steps ! HELP-NEXT: --target= Generate code for the given target diff --git a/flang/test/Driver/fno-integrated-as.f90 b/flang/test/Driver/fno-integrated-as.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/fno-integrated-as.f90 @@ -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" diff --git a/flang/test/Driver/save-temps.f90 b/flang/test/Driver/save-temps.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Driver/save-temps.f90 @@ -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"