tree access_type = TREE_TYPE (e);
   if (TREE_CODE (access_type) == ARRAY_TYPE)
     access_type = TREE_TYPE (access_type);
-  tree arg_type = TREE_TYPE (TREE_TYPE (arg));
+  tree arg_type = TREE_TYPE (arg);
+  if (POINTER_TYPE_P (arg_type))
+    arg_type = TREE_TYPE (arg_type);
   if (TREE_CODE (arg_type) == ARRAY_TYPE)
     arg_type = TREE_TYPE (arg_type);
-
   if (tree access_size = TYPE_SIZE_UNIT (access_type))
     if (TREE_CODE (access_size) == INTEGER_CST)
       {
 
   /* True to include a cast to the accessed type.  */
   const bool access_cast = VOID_TYPE_P (arg_type)
-    || !gimple_canonical_types_compatible_p (access_type, arg_type);
+    || TYPE_MAIN_VARIANT (access_type) != TYPE_MAIN_VARIANT (arg_type);
 
   if (byte_off != 0)
     {
       /* When printing the byte offset for a pointer to a type of
         a different size than char, include a cast to char* first,
         before printing the cast to a pointer to the accessed type.  */
-      tree arg_type = TREE_TYPE (TREE_TYPE (arg));
-      if (TREE_CODE (arg_type) == ARRAY_TYPE)
-       arg_type = TREE_TYPE (arg_type);
       offset_int arg_size = 0;
       if (tree size = TYPE_SIZE (arg_type))
        arg_size = wi::to_offset (size);
 
--- /dev/null
+/* PR c/98597 - ICE in -Wuninitialized printing a MEM_REF
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+struct shared_count {
+  shared_count () { }
+  shared_count (shared_count &r)
+    : pi (r.pi) { }     // { dg-warning "\\\[-Wuninitialized" }
+  int pi;
+};
+
+// There's another (redundant) -Wuninitialized on the line below.
+struct shared_ptr {
+  int ptr;
+  shared_count refcount;
+};
+
+struct Bar {
+  Bar (int, shared_ptr);
+};
+
+void g () {
+  shared_ptr foo;
+  Bar (0, foo);
+}
+
+// Prune out duplicates.
+// { dg-prune-output "-Wuninitialized" }
 
--- /dev/null
+/* PR c/98592 - ICE in gimple_canonical_types_compatible_p while formatting
+   a MEM_REF
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+void f (int);
+
+void vlaNx3_to_pia1 (int n)
+{
+  int a[n][3];
+
+  /* The VLA isn't formatted correctly due to PR 98587.  Just verify
+     there is no ICE and a warning is issued.  */
+  f (((*(int(*)[4])&a[1][2]))[3]);      // { dg-warning "\\\[-Wuninitialized" }
+}
+
+void vlaNxN_to_pia1 (int n)
+{
+  int a[n][n];
+
+  /* Same as above.  */
+  f (((*(int(*)[4])&a[1][2]))[3]);      // { dg-warning "\\\[-Wuninitialized" }
+}
+
+void vlaNxN_to_pvla4xN (int n)
+{
+  int a[n][n];
+
+  /* Same as above.  */
+  f (((*(int(*)[4][n])&a[1][2]))[3][4]);  // { dg-warning "\\\[-Wuninitialized" }
+}
+
+void vlaN_to_pia2 (int n)
+{
+  int a[n];
+
+  /* Same as above.  */
+  f (((*(int(*)[3][4])&a[1]))[2][3]);   // { dg-warning "\\\[-Wuninitialized" }
+}
+
+void vlaN_to_pvlaNx4 (int n)
+{
+  int a[n];
+
+  /* Same as above.  */
+  f (((*(int(*)[n][4])&a[1]))[1][3]);   // { dg-warning "\\\[-Wuninitialized" }
+}