]> gcc.gnu.org Git - gcc.git/commitdiff
c-family: Fix up MEM_REF printing [PR95580]
authorJakub Jelinek <jakub@redhat.com>
Tue, 9 Jun 2020 06:39:36 +0000 (08:39 +0200)
committerJakub Jelinek <jakub@redhat.com>
Sun, 14 Jun 2020 10:06:23 +0000 (12:06 +0200)
The C FE in the MEM_REF printing ICEs if the type of the first argument
(which due to useless pointer conversions can be an arbitrary type) is a
pointer to an incomplete type.  The code just wants to avoid printing a cast
if it is a pointer to single byte elements.

2020-06-09  Jakub Jelinek  <jakub@redhat.com>

PR c/95580
* c-pretty-print.c (c_pretty_printer::unary_expression): Handle the
case when MEM_REF's first argument has type pointer to incomplete type.

* gcc.dg/pr95580.c: New test.

(cherry picked from commit d6dbb71e468d0db561cc9eca99eeaca1efb81c11)

gcc/c-family/c-pretty-print.c
gcc/testsuite/gcc.dg/pr95580.c [new file with mode: 0644]

index 32f30f2d452692a610269b835e86d71f4e29273e..134b6e4cdcff955aeef8499131217bb3e4420e51 100644 (file)
@@ -1789,8 +1789,9 @@ c_pretty_printer::unary_expression (tree e)
          if (!integer_zerop (TREE_OPERAND (e, 1)))
            {
              pp_c_left_paren (this);
-             if (!integer_onep (TYPE_SIZE_UNIT
-                                (TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0))))))
+             tree type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (e, 0)));
+             if (TYPE_SIZE_UNIT (type) == NULL_TREE
+                 || !integer_onep (TYPE_SIZE_UNIT (type)))
                pp_c_type_cast (this, ptr_type_node);
            }
          pp_c_cast_expression (this, TREE_OPERAND (e, 0));
diff --git a/gcc/testsuite/gcc.dg/pr95580.c b/gcc/testsuite/gcc.dg/pr95580.c
new file mode 100644 (file)
index 0000000..8242515
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR c/95580 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -W -fno-tree-dce" } */
+
+void bar (void);
+
+void
+foo (int x)
+{
+  if (x == 0)
+    {
+      void *p = __builtin_malloc (4);
+      ((char *)p)[1] ^= 1;     /* { dg-warning "may be used uninitialized" "" { xfail *-*-* } } */
+    }
+  bar ();
+}
This page took 0.079895 seconds and 5 git commands to generate.