Commit Graph

12 Commits

Author SHA1 Message Date
Richard Smith 38a4b05cf0 Use zeroinitializer for (trailing zero portion of) large array initializers
more reliably.

This re-commits r333044 with a fix for PR37560.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333141 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23 23:41:38 +00:00
Hans Wennborg afb957d151 Revert r333044 "Use zeroinitializer for (trailing zero portion of) large array initializers"
It caused asserts, see PR37560.

> Use zeroinitializer for (trailing zero portion of) large array initializers
> more reliably.
>
> Clang has two different ways it emits array constants (from InitListExprs and
> from APValues), 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.
>
> Differential Revision: https://reviews.llvm.org/D47166

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333067 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23 08:24:01 +00:00
Richard Smith 5ae11cdd08 Use zeroinitializer for (trailing zero portion of) large array initializers
more reliably.

Clang has two different ways it emits array constants (from InitListExprs and
from APValues), 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.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333044 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23 00:09:29 +00:00
Richard Smith 1bc857476c Revert r332847; it caused us to miscompile certain forms of reference initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332886 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 20:36:58 +00:00
Serge Pavlov 6b450481a2 [CodeGen] Recognize more cases of zero initialization
If a variable has an initializer, codegen tries to build its value. If
the variable is large in size, building its value requires substantial
resources. It causes strange behavior from user viewpoint: compilation
of huge zero initialized arrays like:

    char data_1[2147483648u] = { 0 };

consumes enormous amount of time and memory.

With this change codegen tries to determine if variable initializer is
equivalent to zero initializer. In this case variable value is not
constructed.

This change fixes PR18978.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332847 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 16:09:54 +00:00
Richard Smith fad0d79196 PR32044: Fix some cases where we would confuse a transparent init-list expression with an aggregate init.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296033 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-23 22:41:47 +00:00
David Blaikie ca540a101d Update Clang tests to handle explicitly typed gep changes in LLVM.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230783 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-27 19:18:17 +00:00
Hal Finkel 4cdf252c12 Mark C++ reference parameters as dereferenceable
Because references must be initialized using some evaluated expression, they
must point to something, and a callee can assume the reference parameter is
dereferenceable. Taking advantage of a new attribute just added to LLVM, mark
them as such.

Because dereferenceability in addrspace(0) implies nonnull in the backend, we
don't need both attributes. However, we need to know the size of the object to
use the dereferenceable attribute, so for incomplete types we still emit only
nonnull.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213386 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-18 15:52:10 +00:00
Richard Smith 461cfc5c98 A non-trivial array-fill expression isn't necessarily a CXXConstructExpr. It
could be an InitListExpr that runs constructors in C++11 onwards. Fixes a
recent regression (introduced in r210091).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210954 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-13 23:04:49 +00:00
Nick Lewycky 9e97cc3391 Add 'nonnull' parameter or return attribute when producing an llvm pointer type in a function type where the C++ type is a reference. Update the tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209723 91177308-0d34-0410-b5e6-96231b3b80d8
2014-05-28 09:56:42 +00:00
Richard Smith 5dfced87dc Slightly generalize FileCheck patterns to unbreak -Asserts builds.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156783 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-14 22:06:02 +00:00
Richard Smith 13ec9100ca Implement IRGen for C++11's "T{1, 2, 3}", where T is an aggregate and the
expression is treated as an lvalue.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156781 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-14 21:57:21 +00:00