[PATCH] D68115: Zero initialize padding in unions
Vitaly Buka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 26 18:43:51 PDT 2019
vitalybuka created this revision.
vitalybuka added reviewers: rsmith, jfb.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.
vitalybuka edited the summary of this revision.
vitalybuka edited the summary of this revision.
Existing implementation puts undef into padding bits which almost always
compiled into zeroes. However with -ftrivial-auto-var-init=pattern those undefs
became 0xAA pattern and break some code. We need to zero initialized them.
C++ requires zeroes in padding bit.
11.6 Initializers
(6.3) — if T is a (possibly cv-qualified) union type, its padding bits (6.7) are initialized to zero bits
Looks like C does not require, as union is not aggregate, but a lot of code already relies on this behavior.
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 is a union, the first named member is initialized (recursively) according to these rules, and
any padding is initialized to zero bits;
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68115
Files:
clang/lib/CodeGen/CGExprConstant.cpp
clang/test/CodeGen/2008-08-07-AlignPadding1.c
clang/test/CodeGen/64bit-swiftcall.c
clang/test/CodeGen/arm-swiftcall.c
clang/test/CodeGen/designated-initializers.c
clang/test/CodeGen/init.c
clang/test/CodeGen/union-init2.c
clang/test/CodeGen/windows-swiftcall.c
clang/test/CodeGenCXX/auto-var-init.cpp
clang/test/CodeGenCXX/const-init-cxx11.cpp
clang/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
clang/test/CodeGenCXX/designated-init.cpp
clang/test/CodeGenCXX/static-init.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68115.222068.patch
Type: text/x-patch
Size: 21695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190927/ed28c7ab/attachment-0001.bin>
More information about the cfe-commits
mailing list