[cfe-commits] r120722 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGenCXX/value-init.cpp
Douglas Gregor
dgregor at apple.com
Thu Dec 2 10:44:32 PST 2010
On Dec 2, 2010, at 10:29 AM, Chris Lattner wrote:
> Author: lattner
> Date: Thu Dec 2 12:29:00 2010
> New Revision: 120722
>
> URL: http://llvm.org/viewvc/llvm-project?rev=120722&view=rev
> Log:
> fix PR8726 by teaching the aggregate init optimization code to handle
> structs with references in them correctly.
>
>
> Modified:
> cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> cfe/trunk/test/CodeGenCXX/value-init.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=120722&r1=120721&r2=120722&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Dec 2 12:29:00 2010
> @@ -738,6 +738,39 @@
> if (ILE == 0 || !CGF.getTypes().isZeroInitializable(ILE->getType()))
> return CGF.getContext().getTypeSize(E->getType())/8;
>
> + // InitListExprs for structs have to be handled carefully. If there are
> + // reference members, we need to consider the size of the reference, not the
> + // referencee. InitListExprs for unions and arrays can't have references.
> + if (!E->getType()->isUnionType() && !E->getType()->isArrayType()) {
> + RecordDecl *SD = E->getType()->getAs<RecordType>()->getDecl();
> + uint64_t NumNonZeroBytes = 0;
While I know that "if it's not a union or an array, it's a struct" holds for aggregates, it feels needlessly indirect. How about:
if (const RecordType *Record = E->getType()->getAs<RecordType>()) {
if (!Record->getDecl()->isUnion()) {
}
}
?
It's also more efficient ;)
- Doug
More information about the cfe-commits
mailing list