[PATCH] D68115: Zero initialize padding in unions

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 16:06:44 PDT 2019


vitalybuka marked an inline comment as done.
vitalybuka added inline comments.


================
Comment at: clang/test/CodeGen/init.c:197
   // CHECK-LABEL: @nonzeroPaddedUnionMemset(
-  // CHECK-NOT: store
-  // CHECK-NOT: memcpy
-  // CHECK: call void @llvm.memset.p0i8.i32(i8* {{.*}}, i8 -16, i32 36, i1 false)
+  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 {{.*}}, i8* align 4 {{.*}} [[INIT_PADDEDUNION]], {{.*}}, i32 36, i1 false)
 }
----------------
vitalybuka wrote:
> hubert.reinterpretcast wrote:
> > This is C++ aggregate initialization and not value-initialization. The wording you quoted from the C++ standard is for zero-initialization, which might be part of value initialization, but you have not shown that aggregate initialization of a union involves zero-initialization of that union.
> reading this more I don't see any evidence that either C++ or C requires padding initialization.
> Reading this I expect that all function here should be equivalent https://godbolt.org/z/1O_9-e
> But they are not. Clang and GCC initialized padding after the first member.
So if go trough "aggregates" then nothing is said about padding in union.
If we go trough "list-initialization" then value initialization should be applied, part of which is zero initialization. 
If so union padding should be initialized.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68115





More information about the cfe-commits mailing list