From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id 89B35386F81C; Thu, 27 Aug 2020 18:05:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89B35386F81C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598551507; bh=3uHi7utT51E26AgZROfYyPihZ8k1RqpCfkmbyANaNwc=; h=From:To:Subject:Date:From; b=brrVt8HNatDiJl53rZzWaZMx2cd0pF6d9Osv7bta9g0UwQNHij9xxWkvKeQi7zer0 +97GrRERRTRsank3mjTwRVr3eRh46Imn4t7gh5jAXxRMuaFmb9lGKlkv2lGuE2PUcZ 5D4ER/QJ+XcxSPTAtIaufe8sdywIWn4MMB7nyoy0= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] Fix NULL pointer dereference in doloop_contained_function_call. X-Act-Checkin: gcc X-Git-Author: Thomas Koenig X-Git-Refname: refs/heads/devel/c++-modules X-Git-Oldrev: 5c64df80df274c753bfc8415bd902e1180e76f6a X-Git-Newrev: a5da50ed65a835dc1ed6179e3f2b6164fd6e4969 Message-Id: <20200827180507.89B35386F81C@sourceware.org> Date: Thu, 27 Aug 2020 18:05:07 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Aug 2020 18:05:07 -0000 https://gcc.gnu.org/g:a5da50ed65a835dc1ed6179e3f2b6164fd6e4969 commit a5da50ed65a835dc1ed6179e3f2b6164fd6e4969 Author: Thomas Koenig Date: Mon Aug 10 19:10:26 2020 +0200 Fix NULL pointer dereference in doloop_contained_function_call. gcc/fortran/ChangeLog: PR fortran/96556 * frontend-passes.c (doloop_contained_function_call): Do not dereference a NULL pointer for value.function.esym. gcc/testsuite/ChangeLog: PR fortran/96556 * gfortran.dg/do_check_15.f90: New test. Diff: --- gcc/fortran/frontend-passes.c | 3 +- gcc/testsuite/gfortran.dg/do_check_15.f90 | 58 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 6bcb1f06b1c..83f6fd804b1 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -2329,7 +2329,8 @@ doloop_contained_function_call (gfc_expr **e, gfc_symbol *sym, *do_var; contained_info *info; - if (expr->expr_type != EXPR_FUNCTION || expr->value.function.isym) + if (expr->expr_type != EXPR_FUNCTION || expr->value.function.isym + || expr->value.function.esym == NULL) return 0; sym = expr->value.function.esym; diff --git a/gcc/testsuite/gfortran.dg/do_check_15.f90 b/gcc/testsuite/gfortran.dg/do_check_15.f90 new file mode 100644 index 00000000000..f67452b4660 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/do_check_15.f90 @@ -0,0 +1,58 @@ +! { dg-do compile } +! PR fortran/96556 - this used to cause an ICE. +! Test case by Juergen Reuter. +module polarizations + + implicit none + private + + type :: smatrix_t + private + integer :: dim = 0 + integer :: n_entry = 0 + integer, dimension(:,:), allocatable :: index + contains + procedure :: write => smatrix_write + end type smatrix_t + + type, extends (smatrix_t) :: pmatrix_t + private + contains + procedure :: write => pmatrix_write + procedure :: normalize => pmatrix_normalize + end type pmatrix_t + +contains + + subroutine msg_error (string) + character(len=*), intent(in), optional :: string + end subroutine msg_error + + subroutine smatrix_write (object) + class(smatrix_t), intent(in) :: object + end subroutine smatrix_write + + subroutine pmatrix_write (object) + class(pmatrix_t), intent(in) :: object + call object%smatrix_t%write () + end subroutine pmatrix_write + + subroutine pmatrix_normalize (pmatrix) + class(pmatrix_t), intent(inout) :: pmatrix + integer :: i, hmax + logical :: fermion, ok + do i = 1, pmatrix%n_entry + associate (index => pmatrix%index(:,i)) + if (index(1) == index(2)) then + call error ("diagonal must be real") + end if + end associate + end do + contains + subroutine error (msg) + character(*), intent(in) :: msg + call pmatrix%write () + end subroutine error + end subroutine pmatrix_normalize + +end module polarizations