c: ignore initializers for elements of variable-size types [PR93577]
Bug 93577, apparently a regression (although it isn't very clear to me exactly when it was introduced; tests I made with various past compilers produced inconclusive results, including e.g. ICEs appearing with 64-bit-host compilers for some versions but not 32-bit-host compilers for the same versions) is an C front-end tree-checking ICE processing initializers for structs using the VLA-in-struct extension. There is an error for such initializers, but other processing that still takes place for them results in the ICE. This patch ensures that processing of initializers for variable-size types stops earlier to avoid the code that results in the ICE (and ensures it stops earlier for error_mark_node to avoid ICEs in the check for variable-size types), adjusts the conditions for the "empty scalar initializer" diagnostic to avoid consequent excess errors in the case of a bad type name, and adds tests for a few variations on what such initializers might look like, as well as tests for cases identified from ICEs seen with an earlier version of this patch. Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/93577 gcc/c: * 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. gcc/testsuite: * 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.
This commit is contained in:
parent
8c044c6577
commit
c9d70946b3
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -8759,7 +8759,7 @@ pop_init_level (location_t loc, int implicit,
|
||||
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;
|
||||
}
|
||||
@ -8836,8 +8836,8 @@ set_designator (location_t loc, bool array,
|
||||
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
|
||||
@ -8845,6 +8845,12 @@ set_designator (location_t loc, bool array,
|
||||
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);
|
||||
@ -9955,8 +9961,14 @@ process_init_element (location_t loc, struct c_expr value, bool implicit,
|
||||
}
|
||||
|
||||
/* 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
|
||||
|
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
16
gcc/testsuite/gcc.dg/pr93577-1.c
Normal file
16
gcc/testsuite/gcc.dg/pr93577-1.c
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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" } */
|
||||
}
|
16
gcc/testsuite/gcc.dg/pr93577-2.c
Normal file
16
gcc/testsuite/gcc.dg/pr93577-2.c
Normal file
@ -0,0 +1,16 @@
|
||||
/* 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" } */
|
||||
}
|
17
gcc/testsuite/gcc.dg/pr93577-3.c
Normal file
17
gcc/testsuite/gcc.dg/pr93577-3.c
Normal file
@ -0,0 +1,17 @@
|
||||
/* 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" } */
|
||||
}
|
17
gcc/testsuite/gcc.dg/pr93577-4.c
Normal file
17
gcc/testsuite/gcc.dg/pr93577-4.c
Normal file
@ -0,0 +1,17 @@
|
||||
/* 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" } */
|
||||
}
|
11
gcc/testsuite/gcc.dg/pr93577-5.c
Normal file
11
gcc/testsuite/gcc.dg/pr93577-5.c
Normal file
@ -0,0 +1,11 @@
|
||||
/* 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" } */
|
||||
}
|
11
gcc/testsuite/gcc.dg/pr93577-6.c
Normal file
11
gcc/testsuite/gcc.dg/pr93577-6.c
Normal file
@ -0,0 +1,11 @@
|
||||
/* 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" } */
|
||||
}
|
@ -10,6 +10,4 @@ void
|
||||
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 } */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user