aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2021-10-22 23:23:06 +0200
committerTobias Burnus <tobias@codesourcery.com>2021-10-22 23:48:57 +0200
commit24e99e6ec1cc57f3660c00ff677c7feb16aa94d2 (patch)
treee8289755fc57f2a57dbbd94b2a2b2d5a6328f66b /gcc
parentaa41680e481456917824e3794c526521b9520589 (diff)
downloadgcc-24e99e6ec1cc57f3660c00ff677c7feb16aa94d2.zip
gcc-24e99e6ec1cc57f3660c00ff677c7feb16aa94d2.tar.gz
gcc-24e99e6ec1cc57f3660c00ff677c7feb16aa94d2.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/trans-expr.c1
-rw-r--r--gcc/testsuite/gfortran.dg/bind-c-intent-out-2.f9039
2 files changed, 40 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 29697e6..2d7f9e0 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 0000000..fe8f606
--- /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