c: After issuing errors about array size, for error-recovery don't make the array...
authorJakub Jelinek <jakub@redhat.com>
Sat, 28 Mar 2020 09:30:31 +0000 (10:30 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sat, 28 Mar 2020 09:30:31 +0000 (10:30 +0100)
After we report various errors about array size, we set for error-recovery
the size to be 1, but because size_int_const is false, it still means we
pretend the array is a VLA, can emit a second diagnostics in that case etc.
E.g.
$ ./cc1.unpatched -quiet a.c
a.c:1:5: error: size of array ‘f’ has non-integer type
    1 | int f[100.0];
      |     ^
a.c:1:1: warning: variably modified ‘f’ at file scope
    1 | int f[100.0];
      | ^~~
$ ./cc1 -quiet a.c
a.c:1:5: error: size of array ‘f’ has non-integer type
    1 | int f[100.0];
      |     ^

2020-03-28  Jakub Jelinek  <jakub@redhat.com>

PR c/93573
* c-decl.c (grokdeclarator): After issuing errors, set size_int_const
to true after setting size to integer_one_node.

* gcc.dg/pr93573-1.c: New test.
* gcc.dg/pr93573-2.c: New test.

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

index 52c296c00ae0e19159a196c373f9970db04c96d7..86ad683a6cb0abe66438dc23a95138f07a8282af 100644 (file)
@@ -1,5 +1,9 @@
 2020-03-28  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/93573
+       * c-decl.c (grokdeclarator): After issuing errors, set size_int_const
+       to true after setting size to integer_one_node.
+
        PR tree-optimization/94329
        * tree-ssa-reassoc.c (reassociate_bb): When calling reassoc_remove_stmt
        on the last stmt in a bb, make sure gsi_prev isn't done immediately
index 80fe3186759adbbc0dc05ffcadb82f06612d05b7..b31d99fcfafb0ac79969427241661516c1f41f13 100644 (file)
@@ -6416,6 +6416,7 @@ grokdeclarator (const struct c_declarator *declarator,
                      error_at (loc,
                                "size of unnamed array has non-integer type");
                    size = integer_one_node;
+                   size_int_const = true;
                  }
                /* This can happen with enum forward declaration.  */
                else if (!COMPLETE_TYPE_P (TREE_TYPE (size)))
@@ -6427,6 +6428,7 @@ grokdeclarator (const struct c_declarator *declarator,
                      error_at (loc, "size of unnamed array has incomplete "
                                "type");
                    size = integer_one_node;
+                   size_int_const = true;
                  }
 
                size = c_fully_fold (size, false, &size_maybe_const);
@@ -6451,6 +6453,7 @@ grokdeclarator (const struct c_declarator *declarator,
                        else
                          error_at (loc, "size of unnamed array is negative");
                        size = integer_one_node;
+                       size_int_const = true;
                      }
                    /* Handle a size folded to an integer constant but
                       not an integer constant expression.  */
index 3e51175368cc435172184a962a8785a615c1ac39..6c3cb7016265f9e841c7a022cda60bef49db77c9 100644 (file)
@@ -1,5 +1,9 @@
 2020-03-28  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c/93573
+       * gcc.dg/pr93573-1.c: New test.
+       * gcc.dg/pr93573-2.c: New test.
+
        PR tree-optimization/94329
        * gfortran.dg/pr94329.f90: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr93573-1.c b/gcc/testsuite/gcc.dg/pr93573-1.c
new file mode 100644 (file)
index 0000000..26ec9b7
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR c/93573 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void bar ();
+
+void
+foo (char a)
+{
+  union C { int d[100.0]; char *e; };  /* { dg-error "has non-integer type" } */
+  bar ((union C) &a);
+}
diff --git a/gcc/testsuite/gcc.dg/pr93573-2.c b/gcc/testsuite/gcc.dg/pr93573-2.c
new file mode 100644 (file)
index 0000000..f880945
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR c/93573 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int f[100.0];  /* { dg-error "has non-integer type" } */
+                /* { dg-bogus "variably modified .f. at file scope" "" { target *-*-* } .-1 } */