Fix ICE when associating a pointer to void (c_ptr) by looking at the
compatibility of the type hierarchy.
PR fortran/118789
gcc/fortran/ChangeLog:
* trans-stmt.cc (trans_associate_var): Compare pointed to types when
expr to associate is already a pointer.
gcc/testsuite/ChangeLog:
* gfortran.dg/associate_73.f90: New test.
tmp = se.expr;
}
}
- if (!POINTER_TYPE_P (TREE_TYPE (se.expr)))
+ /* For non-pointer types in se.expr, the first condition holds.
+ For pointer or reference types in se.expr, a double TREE_TYPE ()
+ is possible and an associate variable always is a pointer. */
+ if (!POINTER_TYPE_P (TREE_TYPE (se.expr))
+ || TREE_TYPE (TREE_TYPE (se.expr))
+ != TREE_TYPE (TREE_TYPE (sym->backend_decl)))
tmp = gfc_build_addr_expr (tmp, se.expr);
}
--- /dev/null
+!{ dg-do compile }
+
+! Check associate to a "void *" does not ICE.
+! Contributed by Matthias Klose <doko@gcc.gnu.org>
+! and Steve Kargl <kargls@comcast.net>
+
+module pr118789
+
+ implicit none
+
+ CONTAINS
+
+ subroutine fckit_c_nodelete(cptr) bind(c)
+ use, intrinsic :: iso_c_binding
+ type(c_ptr), value :: cptr
+ associate( unused_ => cptr )
+ end associate
+ end subroutine
+
+end module
+