[PATCH] D61280: Variable auto-init: don't initialize aggregate padding of all aggregates

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 30 13:49:19 PDT 2019


jfb added a comment.

In D61280#1485073 <https://reviews.llvm.org/D61280#1485073>, @rjmccall wrote:

> IIRC, C says *members* are initialized as if they were in static storage, which might mean that their interior padding should be zeroed, but I don't think says anything about the padding in the enclosing aggregate.  But I think zero-initializing padding is probably the right thing to do in general under this flag.


Quoth the Standard:

C17 6.7.9 Initialization ❡21
If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.

C17 6.7.9 Initialization ❡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 and padding is initialized to zero bits;
- if it is a union, the first named member is initialized (recessively) according to these rules, and any padding is initialized to zero bits;

🙂


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61280/new/

https://reviews.llvm.org/D61280





More information about the cfe-commits mailing list