+2020-03-05 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/93577
+ * c-typeck.c (pop_init_level): Do not diagnose initializers as
+ empty when initialized type is error_mark_node.
+ (set_designator, process_init_element): Ignore initializers for
+ elements of a variable-size type or of error_mark_node.
+
2020-03-01 Martin Sebor <msebor@redhat.com>
PR middle-end/93926
the element, after verifying there is just one. */
if (vec_safe_is_empty (constructor_elements))
{
- if (!constructor_erroneous)
+ if (!constructor_erroneous && constructor_type != error_mark_node)
error_init (loc, "empty scalar initializer");
ret.value = error_mark_node;
}
enum tree_code subcode;
/* Don't die if an entire brace-pair level is superfluous
- in the containing level. */
- if (constructor_type == NULL_TREE)
+ in the containing level, or for an erroneous type. */
+ if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
return true;
/* If there were errors in this designator list already, bail out
if (designator_erroneous)
return true;
+ /* Likewise for an initializer for a variable-size type. Those are
+ diagnosed in digest_init. */
+ if (COMPLETE_TYPE_P (constructor_type)
+ && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
+ return true;
+
if (!designator_depth)
{
gcc_assert (!constructor_range_stack);
}
/* Ignore elements of a brace group if it is entirely superfluous
- and has already been diagnosed. */
- if (constructor_type == NULL_TREE)
+ and has already been diagnosed, or if the type is erroneous. */
+ if (constructor_type == NULL_TREE || constructor_type == error_mark_node)
+ return;
+
+ /* Ignore elements of an initializer for a variable-size type.
+ Those are diagnosed in digest_init. */
+ if (COMPLETE_TYPE_P (constructor_type)
+ && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST)
return;
if (!implicit && warn_designated_init && !was_designated
+2020-03-05 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/93577
+ * gcc.dg/pr93577-1.c, gcc.dg/pr93577-2.c, gcc.dg/pr93577-3.c,
+ gcc.dg/pr93577-4.c, gcc.dg/pr93577-5.c, gcc.dg/pr93577-6.c: New
+ tests.
+ * gcc.dg/vla-init-1.c: Expect fewer errors about VLA initializer.
+
2020-03-05 Jeff Law <law@redhat.com>
PR tree-optimization/91890
--- /dev/null
+/* Test ICE with variable-size struct initializer: bug 93577. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int c)
+{
+ struct s
+ {
+ int x[c];
+ struct
+ {
+ int z;
+ } nest;
+ } v = { 1, 2 }; /* { dg-error "variable-sized object may not be initialized" } */
+}
--- /dev/null
+/* Test ICE with variable-size struct initializer: bug 93577. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int c)
+{
+ struct s
+ {
+ int x[c];
+ struct
+ {
+ int a, b;
+ } nest;
+ } v = { .nest.b = 1, .nest.a = 2 }; /* { dg-error "variable-sized object may not be initialized" } */
+}
--- /dev/null
+/* Test ICE with variable-size struct initializer: bug 93577. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int c)
+{
+ struct s
+ {
+ int a;
+ int x[c];
+ struct
+ {
+ int a, b;
+ } nest;
+ } v = { .a = 2, .nest.b = 1 }; /* { dg-error "variable-sized object may not be initialized" } */
+}
--- /dev/null
+/* Test ICE with variable-size struct initializer: bug 93577. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f (int c)
+{
+ struct s
+ {
+ int a;
+ int x[c];
+ struct
+ {
+ int a, b;
+ } nest;
+ } v[2] = { [1].nest.b = 1 }; /* { dg-error "variable-sized object may not be initialized" } */
+}
--- /dev/null
+/* Test ICE with designated initializer in compound literal with bad
+ type name (ICE seen with early version of fix for bug 93577 but not
+ covered in other tests). */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void *
+f (void)
+{
+ return &(const bad_type) { .a = 0 }; /* { dg-error "unknown type name" } */
+}
--- /dev/null
+/* Test ICE with designated initializer in compound literal with bad
+ type name (ICE seen with early version of fix for bug 93577 but not
+ covered in other tests). */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void *
+f (void)
+{
+ return &(const bad_type) { [0] = 0 }; /* { dg-error "unknown type name" } */
+}
foo (void)
{
int x[a] = { 1 }; /* { dg-error "variable-sized object may not be initialized" "VLA init" } */
- /* { dg-warning "excess elements in array initializer" "excess" { target *-*-* } .-1 } */
- /* { dg-message "near initialization" "near" { target *-*-* } .-2 } */
}