Skip to content

Commit def8ab8

Browse files
committed
[flang] Remove implicit assumption of fixed-form
This change ensures that flang no longer assumes fixed-form when using `-x f95`. The only case where fixed-form is still assumed is when `-x f95` is used with `.i` files, unless explicitly overridden by the user.
1 parent 30fa7a2 commit def8ab8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
817817

818818
// 'flang -E' always produces output that is suitable for use as fixed form
819819
// Fortran. However it is only valid free form source if the original is also
820-
// free form.
821-
if (InputType == types::TY_PP_Fortran &&
820+
// free form. Ensure this logic does not incorrectly assume fixed-form for
821+
// cases where it shouldn't, such as `flang -x f95 foo.f90`.
822+
bool isAtemporaryPreprocessedFile =
823+
Input.isFilename() &&
824+
llvm::sys::path::extension(Input.getFilename())
825+
.ends_with(types::getTypeTempSuffix(InputType, /*CLStyle=*/false));
826+
if (InputType == types::TY_PP_Fortran && isAtemporaryPreprocessedFile &&
822827
!Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
823828
CmdArgs.push_back("-ffixed-form");
824829

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! This test verifies that using `-x f95` does not cause the driver to assume
2+
! this file is in fixed-form.
3+
4+
program main
5+
print *, "Hello, World!"
6+
end
7+
8+
! RUN: %flang -### -x f95 %s 2>&1 | FileCheck --check-prefix=PRINT-PHASES %s
9+
! PRINT-PHASES-NOT: -ffixed-form
10+
11+
! RUN: %flang -Werror -fsyntax-only -x f95 %s 2>&1 | FileCheck --check-prefix=COMPILE --allow-empty %s
12+
! COMPILE-NOT: error

0 commit comments

Comments
 (0)