public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-11] Fortran: Avoid running into assert with -fcheck= + UBSAN
@ 2022-03-07 18:38 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2022-03-07 18:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6fd96bd58cf343f5a08b132fd8d4a3ee779c9c5b

commit 6fd96bd58cf343f5a08b132fd8d4a3ee779c9c5b
Author: Tobias Burnus <tobias@codesourcery.com>
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.
    
    (cherry picked from commit 24e99e6ec1cc57f3660c00ff677c7feb16aa94d2)

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 43404702544..924cdbbd4db 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -11735,6 +11735,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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-07 18:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 18:38 [gcc/devel/omp/gcc-11] Fortran: Avoid running into assert with -fcheck= + UBSAN Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).