PR middle-end/90694 - incorrect representation of ADDR_EXPR involving a pointer to...
authorMartin Sebor <msebor@redhat.com>
Sat, 1 Jun 2019 17:27:20 +0000 (17:27 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Sat, 1 Jun 2019 17:27:20 +0000 (11:27 -0600)
gcc/ChangeLog:

PR middle-end/90694
* tree-pretty-print.c (dump_generic_node): Add parentheses.

gcc/testsuite/ChangeLog:

PR middle-end/90694
* gcc.dg/tree-ssa/dump-5.c: New test.

From-SVN: r271838

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/dump-5.c [new file with mode: 0644]
gcc/tree-pretty-print.c

index 491577b8828086a1780750b741ac849328417f8b..20bdc2bec37aca9db029bd6bda022e31654f3484 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-01  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/90694
+       * tree-pretty-print.c (dump_generic_node): Add parentheses.
+
 2019-05-31  Jan Hubicka  <jh@suse.cz>
 
        * alias.c: Include ipa-utils.h.
index 0663f4c07c62267e70267f75ce9147dc68998c92..0108097262b0a7bfbaee8a5122ee6601065d962d 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-01  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/90694
+       * gcc.dg/tree-ssa/dump-5.c: New test.
+
 2019-05-31  Jan Hubicka  <jh@suse.cz>
 
        * g++.dg/lto/alias-1_0.C: New testcase.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dump-5.c b/gcc/testsuite/gcc.dg/tree-ssa/dump-5.c
new file mode 100644 (file)
index 0000000..6807b5e
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR middle-end/90694 - incorrect representation of ADDR_EXPR involving
+   a pointer to array
+   { dg-do compile }
+   { dg-options "-fdump-tree-original" } */
+
+typedef char A8[8];
+
+unsigned f (A8 *pa)
+{
+  return __builtin_strlen (&(*pa)[2]);
+}
+
+/* Veriy the expression is correct in the dump:
+  { dg-final { scan-tree-dump-not "\\\&\\\*pa\\\[2\\\]" "original" } }
+  { dg-final { scan-tree-dump "\\\&\\\(\\\*pa\\\)\\\[2\\\]" "original" } } */
index 4ba9170ddd32e7b8cdd1243eb9b0ac5ef209343b..1d6eae101ee7e27fd261b73761a8a16cb8a7df91 100644 (file)
@@ -1679,9 +1679,17 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
          {
            if (TREE_CODE (TREE_OPERAND (node, 0)) != ADDR_EXPR)
              {
+               /* Enclose pointers to arrays in parentheses.  */
+               tree op0 = TREE_OPERAND (node, 0);
+               tree op0type = TREE_TYPE (op0);
+               if (POINTER_TYPE_P (op0type)
+                   && TREE_CODE (TREE_TYPE (op0type)) == ARRAY_TYPE)
+                 pp_left_paren (pp);
                pp_star (pp);
-               dump_generic_node (pp, TREE_OPERAND (node, 0),
-                                  spc, flags, false);
+               dump_generic_node (pp, op0, spc, flags, false);
+               if (POINTER_TYPE_P (op0type)
+                   && TREE_CODE (TREE_TYPE (op0type)) == ARRAY_TYPE)
+                 pp_right_paren (pp);
              }
            else
              dump_generic_node (pp,