HomePhabricator

[test-suite] Exclude union initialization test

Authored by nikic on Fri, Dec 24, 2:43 AM.

Description

[test-suite] Exclude union initialization test

The pr19687.c test currently checks that a union initialization
with empty initializer list initializes the whole union to zero.
This does not match clang's current implementation. However,
prior to D115924 constant folding ended up evaluating the undef
initialization as zero, making the test still pass.

The relevant sections of the C11 standard are quoted in the following.

From 6.7.9.10:

If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
or thread storage duration is not initialized explicitly, then:

  • if it has pointer type, it is initialized to a null pointer;
  • if it has arithmetic type, it is initialized to (positive or unsigned) zero;
  • if it is an aggregate, every member is initialized (recursively) according to these rules, and any padding is initialized to zero bits;
  • if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits

From 6.7.9.17:

Each brace-enclosed initializer list has an associated current
object. When no designations are present, subobjects of the current
object are initialized in order according to the type of the current
object: array elements in increasing subscript order, structure
members in declaration order, and the first named member of a union.
[...]

From 6.7.9.19:

The initialization shall occur in initializer list order, each
initializer provided for a particular subobject overriding any
previously listed initializer for the same subobject; 151) all
subobjects that are not initialized explicitly shall be initialized
implicitly the same as objects that have static storage duration.

The = {} syntax is a GNU extension. If interpreted equivalently
to = {0} in this case, it only requires the first union member
to be initialized to zero.

There is a draft proposal to standardize the = {} syntax in
C23, though the precise semantics of union initialization remain
an open question at this time.

Differential Revision: https://reviews.llvm.org/D115994