=?utf-8?q?Iñaki?= Amatria Barral <inaki.amat...@appentra.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/127...@github.com>
llvmbot wrote: <!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-flang-driver Author: Iñaki Amatria Barral (inaki-amatria) <details> <summary>Changes</summary> This PR may solve some of the issues described in: https://github.com/llvm/llvm-project/issues/127617. The reason to revert https://github.com/llvm/llvm-project/commit/81d82cac8c4cbd006bf991fd7380de2d72858d1c is detailed in the associated issue. --- Full diff: https://github.com/llvm/llvm-project/pull/127986.diff 5 Files Affected: - (modified) clang/lib/Driver/ToolChains/Flang.cpp (-7) - (modified) flang/lib/Frontend/CompilerInvocation.cpp (+6) - (added) flang/test/Driver/dash-x-f95.f (+35) - (modified) flang/test/Driver/input-from-stdin/input-from-stdin.f90 (+1-1) - (removed) flang/test/Driver/pp-fixed-form.f90 (-19) ``````````diff diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 9ad795edd724d..bb308c45eb64b 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -803,13 +803,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, addFortranDialectOptions(Args, CmdArgs); - // 'flang -E' always produces output that is suitable for use as fixed form - // Fortran. However it is only valid free form source if the original is also - // free form. - if (InputType == types::TY_PP_Fortran && - !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form)) - CmdArgs.push_back("-ffixed-form"); - handleColorDiagnosticsArgs(D, Args, CmdArgs); // LTO mode is parsed by the Clang driver library. diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index f3d9432c62d3b..1b68dee8b169d 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -859,6 +859,12 @@ static void parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts, (currentArg->getOption().matches(clang::driver::options::OPT_cpp)) ? PPMacrosFlag::Include : PPMacrosFlag::Exclude; + // Enable -cpp based on -x unless explicitly disabled with -nocpp + if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x); + dashX && opts.macrosFlag != PPMacrosFlag::Exclude) + opts.macrosFlag = llvm::StringSwitch<PPMacrosFlag>(dashX->getValue()) + .Case("f95-cpp-input", PPMacrosFlag::Include) + .Default(opts.macrosFlag); opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat); opts.preprocessIncludeLines = diff --git a/flang/test/Driver/dash-x-f95.f b/flang/test/Driver/dash-x-f95.f new file mode 100644 index 0000000000000..ae9a426a9d956 --- /dev/null +++ b/flang/test/Driver/dash-x-f95.f @@ -0,0 +1,35 @@ +program main + print *, __FILE__, __LINE__ +end + +! This test verifies that `flang`'s `-x` options behave like `gfortran`'s. +! Specifically: +! - `-x f95` should process the file based on its extension unless overridden. +! - `-x f95-cpp-input` should behave like `-x f95` but with preprocessing +! (`-cpp`) enabled unless overridden. + +! --- +! Ensure the file is treated as fixed-form unless explicitly set otherwise +! --- +! RUN: not %flang -Werror -x f95 -cpp -c %s 2>&1 | FileCheck --check-prefix=SCAN-ERROR %s +! RUN: not %flang -Werror -x f95-cpp-input -c %s 2>&1 | FileCheck --check-prefix=SCAN-ERROR %s + +! SCAN-ERROR: error + +! RUN: %flang -Werror -x f95 -cpp -ffree-form -c %s 2>&1 | FileCheck --check-prefix=NO-SCAN-ERROR --allow-empty %s +! RUN: %flang -Werror -x f95-cpp-input -ffree-form -c %s 2>&1 | FileCheck --check-prefix=NO-SCAN-ERROR --allow-empty %s + +! NO-SCAN-ERROR-NOT: error + +! --- +! Ensure `-cpp` is not enabled by default unless explicitly requested +! --- +! RUN: not %flang -Werror -x f95 -ffree-form -c %s 2>&1 | FileCheck --check-prefix=SEMA-ERROR %s +! RUN: not %flang -Werror -x f95-cpp-input -nocpp -ffree-form -c %s 2>&1 | FileCheck --check-prefix=SEMA-ERROR %s + +! SEMA-ERROR: error + +! RUN: %flang -Werror -x f95 -cpp -ffree-form -c %s 2>&1 | FileCheck --check-prefix=NO-SEMA-ERROR --allow-empty %s +! RUN: %flang -Werror -x f95-cpp-input -ffree-form -c %s 2>&1 | FileCheck --check-prefix=NO-SEMA-ERROR --allow-empty %s + +! NO-SEMA-ERROR-NOT: error diff --git a/flang/test/Driver/input-from-stdin/input-from-stdin.f90 b/flang/test/Driver/input-from-stdin/input-from-stdin.f90 index 285f0751b35d8..1fcc0340a64ba 100644 --- a/flang/test/Driver/input-from-stdin/input-from-stdin.f90 +++ b/flang/test/Driver/input-from-stdin/input-from-stdin.f90 @@ -6,7 +6,7 @@ ! Input type is implicit ! RUN: cat %s | %flang -E -cpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED ! RUN: cat %s | %flang -DNEW -E -cpp - | FileCheck %s --check-prefix=PP-DEFINED -! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED +! RUN: cat %s | %flang -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED ! RUN: cat %s | %flang -DNEW -E -nocpp - | FileCheck %s --check-prefix=PP-NOT-DEFINED ! Input type is explicit diff --git a/flang/test/Driver/pp-fixed-form.f90 b/flang/test/Driver/pp-fixed-form.f90 deleted file mode 100644 index 4695da78763ae..0000000000000 --- a/flang/test/Driver/pp-fixed-form.f90 +++ /dev/null @@ -1,19 +0,0 @@ -!RUN: %flang -save-temps -### %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE -FREE: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90" -FREE-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "free-form-test.i" - -!RUN: %flang -save-temps -### %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED -FIXED: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f" -FIXED-NEXT: "-fc1" {{.*}} "-ffixed-form" {{.*}} "-x" "f95" "fixed-form-test.i" - -!RUN: %flang -save-temps -### -ffree-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FREE-FLAG -FREE-FLAG: "-fc1" {{.*}} "-o" "free-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/free-form-test.f90" -FREE-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffree-form" -FREE-FLAG-NOT: "-ffixed-form" -FREE-FLAG-SAME: "-x" "f95" "free-form-test.i" - -!RUN: %flang -save-temps -### -ffixed-form %S/Inputs/fixed-form-test.f 2>&1 | FileCheck %s --check-prefix=FIXED-FLAG -FIXED-FLAG: "-fc1" {{.*}} "-o" "fixed-form-test.i" {{.*}} "-x" "f95-cpp-input" "{{.*}}/fixed-form-test.f" -FIXED-FLAG-NEXT: "-fc1" {{.*}} "-emit-llvm-bc" "-ffixed-form" -FIXED-FLAG-NOT: "-ffixed-form" -FIXED-FLAG-SAME: "-x" "f95" "fixed-form-test.i" `````````` </details> https://github.com/llvm/llvm-project/pull/127986 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits