diff --git a/test/f90_correct/inc/oop719.mk b/test/f90_correct/inc/oop719.mk new file mode 100644 index 00000000000..0158ed7cf3a --- /dev/null +++ b/test/f90_correct/inc/oop719.mk @@ -0,0 +1,34 @@ +# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +########## Make rule for test oop719 ######## + + +oop719: run + + +build: $(SRC)/oop719.f90 + -$(RM) oop719.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.* + @echo ------------------------------------ building test $@ + -$(CC) -c $(CFLAGS) $(SRC)/check.c -o check.$(OBJX) + -$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/oop719.f90 -o oop719.$(OBJX) + -$(FC) $(FFLAGS) $(LDFLAGS) oop719.$(OBJX) check.$(OBJX) $(LIBS) -o oop719.$(EXESUFFIX) + + +run: + @echo ------------------------------------ executing test oop719 + oop719.$(EXESUFFIX) + +verify: ; + diff --git a/test/f90_correct/lit/oop719.sh b/test/f90_correct/lit/oop719.sh new file mode 100644 index 00000000000..a9dfc621160 --- /dev/null +++ b/test/f90_correct/lit/oop719.sh @@ -0,0 +1,19 @@ +# +# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Shared lit script for each tests. Run bash commands that run tests with make. + +# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t +# RUN: cat %t | FileCheck %S/runmake diff --git a/test/f90_correct/src/oop719.f90 b/test/f90_correct/src/oop719.f90 new file mode 100644 index 00000000000..8771b1b3e31 --- /dev/null +++ b/test/f90_correct/src/oop719.f90 @@ -0,0 +1,59 @@ +! Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +! +! Licensed under the Apache License, Version 2.0 (the "License"); +! you may not use this file except in compliance with the License. +! You may obtain a copy of the License at +! +! http://www.apache.org/licenses/LICENSE-2.0 +! +! Unless required by applicable law or agreed to in writing, software +! distributed under the License is distributed on an "AS IS" BASIS, +! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +! See the License for the specific language governing permissions and +! limitations under the License. + +! Compile with -Mallocatable=03 to exercise the bug fix (disregard if +! -Mallocatable=03 is now the default behavior in the compiler). + +module mod + integer count + type base + integer :: x + end type base + + type comp + class(base), allocatable :: b + contains + final :: dtor + end type comp + +contains + + subroutine dtor(this) + type(comp) :: this + count = count + 1 + end subroutine dtor + + subroutine foo() + type(comp) :: x, y + + allocate(y%b) + y%b%x = 99 + + ! final subroutine, dtor, gets called 3 times (called for x,y, and + ! the temp used in the x = y assignment below). + + x = y + end subroutine foo + +end module mod + +use mod +logical rslt(1), expect(1) +count = 0 +call foo() + +expect = .true. +rslt(1) = count .eq. 3 +call check(rslt, expect, 1) +end diff --git a/tools/flang1/flang1exe/transfrm.c b/tools/flang1/flang1exe/transfrm.c index 7380369c3ac..33bdfaf25f8 100644 --- a/tools/flang1/flang1exe/transfrm.c +++ b/tools/flang1/flang1exe/transfrm.c @@ -3698,12 +3698,7 @@ rewrite_allocatable_assignment(int astasgn, const int std, LOGICAL non_conformab if (DTYG(dtypedest) == TY_DERIVED && !HCCSYMG(sptrdest) && !XBIT(54, 0x4) && allocatable_member(sptrdest)) { handle_allocatable_members(astdest, astsrc, std, 0); - if (!XBIT(54, 0x1) || !is_or_has_poly(sptrdest) || HCCSYMG(sptrsrc)) { - /* pFUnit - must preserve assign if destination is not - * allocatable, but it has polymorphic allocatable members - */ - ast_to_comment(astasgn); - } + ast_to_comment(astasgn); return; } if (STYPEG(sptrdest) == ST_MEMBER && !XBIT(54, 0x4) && XBIT(54, 0x1)) {