Skip to content

Commit b95754f

Browse files
committed
add unit test that triggers ifort18 assignment problem
1 parent 7b86711 commit b95754f

File tree

4 files changed

+135
-1
lines changed

4 files changed

+135
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
! Copyright (c) 2020 Software for Chemistry & Materials BV
2+
!
3+
! This file is part of of the Fortran Template Library.
4+
!
5+
! The Fortran Template Library is free software: you can redistribute it and/or
6+
! modify it under the terms of the GNU Lesser General Public License as
7+
! published by the Free Software Foundation, either version 3 of the License, or
8+
! (at your option) any later version.
9+
!
10+
! The Fortran Template Library is distributed in the hope that it will be
11+
! useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
13+
! General Public License for more details.
14+
!
15+
! You should have received a copy of the GNU Lesser General Public License along
16+
! with the Fortran Template Library. If not, see <http://www.gnu.org/licenses/>.
17+
18+
19+
module AnimalsModule
20+
21+
use ftlStringModule
22+
23+
implicit none
24+
private
25+
26+
type, abstract, public :: AnimalType
27+
type(ftlString) :: name
28+
contains
29+
procedure(MakeSoundInterface), public, deferred :: MakeSound
30+
end type
31+
32+
interface
33+
module subroutine MakeSoundInterface(self)
34+
class(AnimalType), intent(inout) :: self
35+
end subroutine
36+
end interface
37+
38+
type, extends(AnimalType), public :: BirdType
39+
contains
40+
procedure, public :: NewBird
41+
procedure, public :: MakeSound => MakeSoundBird
42+
end type
43+
44+
type, extends(AnimalType), public :: CowType
45+
contains
46+
procedure, public :: NewCow
47+
procedure, public :: MakeSound => MakeSoundCow
48+
end type
49+
50+
type, public :: AnimalCageType
51+
class(AnimalType), allocatable :: animal
52+
end type
53+
54+
contains
55+
56+
subroutine NewBird(self)
57+
class(BirdType), intent(out) :: self
58+
self%name = 'bird'
59+
end subroutine NewBird
60+
61+
subroutine MakeSoundBird(self)
62+
class(BirdType), intent(inout) :: self
63+
print *, self%name%raw, ': Tweet'
64+
end subroutine
65+
66+
subroutine NewCow(self)
67+
class(CowType), intent(out) :: self
68+
self%name = 'cow'
69+
end subroutine NewCow
70+
71+
subroutine MakeSoundCow(self)
72+
class(CowType), intent(inout) :: self
73+
print *, self%name%raw, ': Moo'
74+
end subroutine
75+
76+
77+
end module

makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ $(BUILDDIR)/ftlAlgorithmsTests.o: tests/ftlAlgorithmsTests.F90 $(BUILDDIR)/ftlAr
152152
$(BUILDDIR)/ftlSharedPtrTests.o: tests/ftlSharedPtrTests.F90 $(BUILDDIR)/ftlSharedPtrInt.o | $(BUILDDIR)
153153
$(COMPILER) $(FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
154154

155-
$(BUILDDIR)/ftlStringTests.o: tests/ftlStringTests.F90 $(BUILDDIR)/ftlString.o $(BUILDDIR)/ftlDynArrayString.o | $(BUILDDIR)
155+
$(BUILDDIR)/ftlStringTests.o: tests/ftlStringTests.F90 $(BUILDDIR)/ftlString.o $(BUILDDIR)/ftlDynArrayString.o $(BUILDDIR)/Animals.o | $(BUILDDIR)
156156
$(COMPILER) $(FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
157157

158158
$(BUILDDIR)/ftlRegexTests.o: tests/ftlRegexTests.F90 $(BUILDDIR)/ftlRegex.o | $(BUILDDIR)
@@ -261,3 +261,6 @@ $(BUILDDIR)/Point2D.o: instantiations/derived_types/Point2D.F90 | $(BUILDDIR)
261261

262262
$(BUILDDIR)/Leaky.o: instantiations/derived_types/Leaky.F90 | $(BUILDDIR)
263263
$(COMPILER) $(FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
264+
265+
$(BUILDDIR)/Animals.o: instantiations/derived_types/Animals.F90 $(BUILDDIR)/ftlString.o | $(BUILDDIR)
266+
$(COMPILER) $(FLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@

src/ftlString.F90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ module ftlStringModule
162162
! assignment for ftlString that does the cleanup of the lhs explicitly, to at least fix these memory leaks when using
163163
! ftlStrings ...
164164
generic, public :: assignment(=) => NewCopyOther
165+
! Note: ifort 18 does NOT like to have a defined assignment for ftlString in a couple of scenarios, see the
166+
! testContainingTypeAssignment regression test for ftlString. Relying on the intrinsic assignment makes that test work, but
167+
! will bring back the leaking ...
165168
#endif
166169

167170
! Overloaded operators:

tests/ftlStringTests.F90

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ subroutine ftlStringTests
106106
call testSplitWordsIntoDynArray
107107
call testDynArrayStringSpecialization
108108

109+
! Really exotic tests for specific issues:
110+
111+
#if !defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1900
112+
! This test fails with ifort 18. It's not a super major issue in practice, but it causes a segfault, so let's skip it here,
113+
! so that we can at least run all the tests ...
114+
call testContainingTypeAssignment
115+
#else
116+
write (*,'(A)') 'Skipping ftlStringtestContainingTypeAssignment for ftlString on ifort 18 ...'
117+
#endif
118+
109119
end subroutine
110120

111121

@@ -1792,4 +1802,45 @@ subroutine testDynArrayStringSpecialization
17921802
end subroutine
17931803

17941804

1805+
subroutine testContainingTypeAssignment
1806+
1807+
use AnimalsModule
1808+
1809+
integer :: i
1810+
type(AnimalCageType), allocatable :: cages(:)
1811+
type(AnimalCageType), allocatable :: newcages(:)
1812+
1813+
allocate(cages(3),newcages(3))
1814+
allocate(BirdType :: cages(1)%animal)
1815+
allocate(BirdType :: cages(2)%animal)
1816+
allocate(CowType :: cages(3)%animal)
1817+
do i = 1, 3
1818+
select type (animal => cages(i)%animal)
1819+
type is (BirdType)
1820+
call animal%NewBird
1821+
type is (CowType)
1822+
call animal%NewCow
1823+
end select
1824+
end do
1825+
1826+
ASSERT(allocated(cages(1)%animal%name%raw))
1827+
ASSERT(cages(1)%animal%name == 'bird')
1828+
ASSERT(allocated(cages(2)%animal%name%raw))
1829+
ASSERT(cages(2)%animal%name == 'bird')
1830+
ASSERT(allocated(cages(3)%animal%name%raw))
1831+
ASSERT(cages(3)%animal%name == 'cow')
1832+
1833+
newcages = cages
1834+
deallocate(cages)
1835+
1836+
ASSERT(allocated(newcages(1)%animal%name%raw))
1837+
ASSERT(newcages(1)%animal%name == 'bird')
1838+
ASSERT(allocated(newcages(2)%animal%name%raw))
1839+
ASSERT(newcages(2)%animal%name == 'bird')
1840+
ASSERT(allocated(newcages(3)%animal%name%raw))
1841+
ASSERT(newcages(3)%animal%name == 'cow')
1842+
1843+
end subroutine
1844+
1845+
17951846
end module

0 commit comments

Comments
 (0)