]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/68668 (bogus error: invalid use of array with unspecified bounds)
authorMarek Polacek <polacek@redhat.com>
Mon, 7 Dec 2015 17:52:23 +0000 (17:52 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 7 Dec 2015 17:52:23 +0000 (17:52 +0000)
PR c/68668
* c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use
TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT.

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

From-SVN: r231374

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr68668.c [new file with mode: 0644]

index 468ef9398be6367879831e73bea8fb09d7b53181..0b3351ce960216d0f6dff745814ff644307c477e 100644 (file)
@@ -1,3 +1,9 @@
+2015-12-07  Marek Polacek  <polacek@redhat.com>
+
+       PR c/68668
+       * c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use
+       TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT.
+
 2015-12-04  Eric Botcazou  <ebotcazou@adacore.com>
 
        * c-tree.h (c_build_va_arg): Adjust prototype.
index 9ad821925a0a124ea034724cd5743d79a7e773ff..2da84f264631f8112b0529bb385601eb4e3cf01a 100644 (file)
@@ -6417,6 +6417,13 @@ grokdeclarator (const struct c_declarator *declarator,
          {
            /* Transfer const-ness of array into that of type pointed to.  */
            type = TREE_TYPE (type);
+           if (orig_qual_type != NULL_TREE)
+             {
+               if (orig_qual_indirect == 0)
+                 orig_qual_type = TREE_TYPE (orig_qual_type);
+               else
+                 orig_qual_indirect--;
+             }
            if (type_quals)
              type = c_build_qualified_type (type, type_quals, orig_qual_type,
                                             orig_qual_indirect);
index a9abef303068b0026e90bbfc3afca64e1073d78d..baff32f2c7fb7a556f343e43f4a6e61b58156d64 100644 (file)
@@ -1,3 +1,8 @@
+2015-12-07  Marek Polacek  <polacek@redhat.com>
+
+       PR c/68668
+       * gcc.dg/pr68668.c: New test.
+
 2015-12-07  Vladimir Makarov  <vmakarov@redhat.com>
 
        * gcc.target/i386/pr68349.c (strlen): Rename to my_strlen.
diff --git a/gcc/testsuite/gcc.dg/pr68668.c b/gcc/testsuite/gcc.dg/pr68668.c
new file mode 100644 (file)
index 0000000..d013aa9
--- /dev/null
@@ -0,0 +1,53 @@
+/* PR c/68668 */
+/* { dg-do compile } */
+
+typedef const int T[];
+typedef const int U[1];
+
+int
+fn1 (T p)
+{
+  return p[0];
+}
+
+int
+fn2 (U p[2])
+{
+  return p[0][0];
+}
+
+int
+fn3 (U p[2][3])
+{
+  return p[0][0][0];
+}
+
+int
+fn4 (U *p)
+{
+  return p[0][0];
+}
+
+int
+fn5 (U (*p)[1])
+{
+  return (*p)[0][0];
+}
+
+int
+fn6 (U (*p)[1][2])
+{
+  return (*p)[0][0][0];
+}
+
+int
+fn7 (U **p)
+{
+  return p[0][0][0];
+}
+
+int
+fn8 (U (**p)[1])
+{
+  return (*p)[0][0][0];
+}