diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index e7da8fea3b24c77b6d9bba95ab0c6f558b11db83..f16e1e3b46e3321a19c12e6695baced48ee79dcc 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -2287,7 +2287,12 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block)
 		  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);
 	}
 
diff --git a/gcc/testsuite/gfortran.dg/associate_73.f90 b/gcc/testsuite/gfortran.dg/associate_73.f90
new file mode 100644
index 0000000000000000000000000000000000000000..a5c3ca79b9cfde09a6bd648d1f046ea8f1a7aa5f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/associate_73.f90
@@ -0,0 +1,21 @@
+!{ 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
+