Skip to content
Snippets Groups Projects
Commit 14cfa017 authored by Joseph Myers's avatar Joseph Myers
Browse files

c: Support C2x empty initializer braces

ISO C2x standardizes empty initializer braces {}.  Implement this
feature accordingly.  The basic case was already supported and so just
needed diagnostic adjustments.  However, the standard feature also
includes two cases that were not previously supported: empty
initializer braces for scalars, and empty initializer braces for
VLAs.  Thus, add support for those features as well, updating existing
tests that expected them to be diagnosed.

There was already some gimplifier support for converting
variable-sized initializations with empty CONSTRUCTORs to memset.
However, it didn't apply here; code earlier in gimplify_modify_expr
ended up calling gimplify_init_constructor via
gimplify_modify_expr_rhs, which ended up handling the CONSTRUCTOR in a
way that generated an ICE later.  Add a check for this case earlier in
gimplify_modify_expr to avoid that issue.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/
	* gimplify.cc (gimplify_modify_expr): Convert initialization from
	a variable-size CONSTRUCTOR to memset before call to
	gimplify_modify_expr_rhs.

gcc/c/
	* c-decl.cc (start_decl): Do not diagnose initialization of
	variable-sized objects here.
	* c-parser.cc (c_parser_braced_init): Add argument DECL.  All
	callers changed.
	(c_parser_initializer): Diagnose initialization of variable-sized
	objects other than with braced initializer.
	(c_parser_braced_init): Use pedwarn_c11 for empty initializer
	braces and update diagnostic text.  Diagnose initialization of
	variable-sized objects with nonempty braces.
	* c-typeck.cc (digest_init): Update diagnostic for initialization
	of variable-sized objects.
	(really_start_incremental_init, set_designator)
	(process_init_element): Update comments.
	(pop_init_level): Allow scalar empty initializers.

gcc/testsuite/
	* gcc.dg/c11-empty-init-1.c, gcc.dg/c11-empty-init-2.c,
	gcc.dg/c11-empty-init-3.c, gcc.dg/c2x-empty-init-1.c,
	gcc.dg/c2x-empty-init-2.c, gcc.dg/c2x-empty-init-3.c,
	gcc.dg/gnu2x-empty-init-1.c, gcc.dg/gnu2x-empty-init-2.c: New
	tests.
	* gcc.dg/torture/dfp-default-init-1.c: Also test empty
	initializers.
	* gcc.dg/init-bad-1.c, gcc.dg/noncompile/pr71583.c,
	gcc.dg/pr61096-1.c, gcc.dg/vla-init-2.c, gcc.dg/vla-init-3.c,
	gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Update expected
	diagnostics.
	* gcc.dg/ubsan/c-shift-1.c: Use nonempty initializers for VLA
	initializations expected to be diagnosed.
parent 072d3115
No related branches found
No related tags found
Loading
Showing
with 305 additions and 47 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment