From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 672E83857C52; Fri, 22 Oct 2021 21:49:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 672E83857C52 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4632] Fortran: Avoid running into assert with -fcheck= + UBSAN X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/master X-Git-Oldrev: aa41680e481456917824e3794c526521b9520589 X-Git-Newrev: 24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 Message-Id: <20211022214913.672E83857C52@sourceware.org> Date: Fri, 22 Oct 2021 21:49:13 +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: Fri, 22 Oct 2021 21:49:13 -0000 https://gcc.gnu.org/g:24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 commit r12-4632-g24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 Author: Tobias Burnus Date: Fri Oct 22 23:23:06 2021 +0200 Fortran: Avoid running into assert with -fcheck= + UBSAN PR fortran/92621 gcc/fortran/ * trans-expr.c (gfc_trans_assignment_1): Add STRIP_NOPS. gcc/testsuite/ * gfortran.dg/bind-c-intent-out-2.f90: New test. Diff: --- gcc/fortran/trans-expr.c | 1 + gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 | 39 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 29697e69e75..2d7f9e0fb91 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -11727,6 +11727,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, tmp = INDIRECT_REF_P (lse.expr) ? gfc_build_addr_expr (NULL_TREE, lse.expr) : lse.expr; + STRIP_NOPS (tmp); /* We should only get array references here. */ gcc_assert (TREE_CODE (tmp) == POINTER_PLUS_EXPR diff --git a/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 b/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 new file mode 100644 index 00000000000..fe8f6060f1f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f90 @@ -0,0 +1,39 @@ +! { dg-do run } +! { dg-additional-options "-fsanitize=undefined -fcheck=all" } + +! PR fortran/92621 + +subroutine hello(val) bind(c) + use, intrinsic :: iso_c_binding, only: c_int + + implicit none + + integer(kind=c_int), allocatable, intent(out) :: val(:) + + allocate(val(1)) + val = 2 + return +end subroutine hello + +program alloc_p + + use, intrinsic :: iso_c_binding, only: c_int + + implicit none + + interface + subroutine hello(val) bind(c) + import :: c_int + implicit none + integer(kind=c_int), allocatable, intent(out) :: val(:) + end subroutine hello + end interface + + integer(kind=c_int), allocatable :: a(:) + + allocate(a(1)) + a = 1 + call hello(a) + stop + +end program alloc_p