Skip to content

Commit ea08176

Browse files
authored
fortitude: Enable nonportable-shortcircuit-inquiry rule (#45)
(from fortitude's explanation) Unlike many other languages, the Fortran standard doesn't mandate (or prohibit) short-circuiting in logical expressions, so different compilers have different behaviour when it comes to evaluating such expressions. This is commonly encountered when using present() with an optional dummy argument and checking its value in the same expression. Without short-circuiting, this can lead to segmentation faults when the expression is evaluated if the argument isn't present.
1 parent 32fbffb commit ea08176

3 files changed

Lines changed: 20 additions & 11 deletions

File tree

fortitude.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ ignore = [
44
"star-kind", # don't use integer*4 et al
55
"literal-kind",
66
"unchecked-stat", # TODO: Fix this!
7-
"nonportable-shortcircuit-inquiry", # TODO: Fix this!
87
]
98
line-length = 132
109
show-fixes = true

src/modules/BundleIOModule.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,10 @@ subroutine FMS_WriteFSOME(T1, T2, Tc, filename, firsttime)
271271

272272
! 2. work out if we are opening a new file
273273
file_exists = .true.
274-
if (present(firsttime) .and. firsttime) then
275-
inquire (file=file_name, exist=file_exists)
274+
if (present(firsttime)) then
275+
if (firsttime) then
276+
inquire (file=file_name, exist=file_exists)
277+
end if
276278
end if
277279

278280
! 3. open the file

src/modules/TrajectoryIOModule.f90

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@ subroutine FMS_WriteFAngle(T, file_name, NAngles, iAngle, first_time)
266266
long_file_name = trim(FMSWorkingDir)//file_name
267267

268268
file_existed = .true.
269-
if (present(first_time) .and. first_time) then
270-
inquire (file=long_file_name, exist=file_existed)
269+
if (present(first_time)) then
270+
if (first_time) then
271+
inquire (file=long_file_name, exist=file_existed)
272+
end if
271273
end if
272274

273275
if (.not. file_existed) then
@@ -684,8 +686,10 @@ subroutine FMS_WriteFDistance(T, file_name, NBonds, iBond, first_time)
684686
long_file_name = trim(FMSWorkingDir)//file_name
685687

686688
file_existed = .true.
687-
if (present(first_time) .and. first_time) then
688-
inquire (file=long_file_name, exist=file_existed)
689+
if (present(first_time)) then
690+
if (first_time) then
691+
inquire (file=long_file_name, exist=file_existed)
692+
end if
689693
end if
690694

691695
if (.not. file_existed) then
@@ -778,8 +782,10 @@ subroutine FMS_WriteFMM(T, file_name, first_time)
778782
long_file_name = trim(FMSWorkingDir)//file_name
779783

780784
file_existed = .true.
781-
if (present(first_time) .and. first_time) then
782-
inquire (file=long_file_name, exist=file_existed)
785+
if (present(first_time)) then
786+
if (first_time) then
787+
inquire (file=long_file_name, exist=file_existed)
788+
end if
783789
end if
784790

785791
if (.not. file_existed) then
@@ -838,8 +844,10 @@ subroutine FMS_WriteFPyram(T, file_name, NPyrams, IPyram, first_time)
838844
long_file_name = trim(FMSWorkingDir)//file_name
839845

840846
file_existed = .true.
841-
if (present(first_time) .and. first_time) then
842-
inquire (file=long_file_name, exist=file_existed)
847+
if (present(first_time)) then
848+
if (first_time) then
849+
inquire (file=long_file_name, exist=file_existed)
850+
end if
843851
end if
844852

845853
! create column labels

0 commit comments

Comments
 (0)