[PATCH] D47166: use zeroinitializer for (trailing zero portion of) large array initializers more reliably

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 21 15:49:20 PDT 2018


rsmith created this revision.
rsmith added reviewers: rjmccall, sepavloff.

Clang has two different ways it emits array constants (from `InitListExpr`s and from `APValue`s), and both had some ability to emit `zeroinitializer`, but neither was able to catch all cases where we could use `zeroinitializer` reliably. In particular, emitting from an `APValue` would fail to notice if all the explicit array elements happened to be zero. In addition, for large arrays where only an initial portion has an explicit initializer, we would emit the complete initializer (which could be huge) rather than emitting only the non-zero portion. With this change, when the element would have a suffix of more than 8 zero elements, we emit the array constant as a packed struct of its initial portion followed by a `zeroinitializer` constant for the trailing zero portion.

In passing, I found a bug where `SemaInit` would sometimes walk the entire array when checking an initializer that only covers the first few elements; that's fixed here to unblock testing of the rest.


Repository:
  rC Clang

https://reviews.llvm.org/D47166

Files:
  lib/CodeGen/CGExprConstant.cpp
  lib/Sema/SemaInit.cpp
  test/CodeGen/init.c
  test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  test/SemaCXX/aggregate-initialization.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47166.147895.patch
Type: text/x-patch
Size: 10602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180521/a2d95653/attachment-0001.bin>


More information about the cfe-commits mailing list