[cfe-commits] r133235 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp lib/Sema/SemaExpr.cpp test/CodeGenCXX/compound-literals.cpp

Douglas Gregor dgregor at apple.com
Fri Jun 17 09:44:40 PDT 2011


On Jun 17, 2011, at 3:23 AM, Eli Friedman wrote:

> On Thu, Jun 16, 2011 at 9:59 PM, Douglas Gregor <dgregor at apple.com> wrote:
>> Author: dgregor
>> Date: Thu Jun 16 23:59:12 2011
>> New Revision: 133235
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=133235&view=rev
>> Log:
>> Implement proper support for generating code for compound literals in
>> C++, which means:
>>  - binding the temporary as needed in Sema, so that we generate the
>>  appropriate call to the destructor, and
>>  - emitting the compound literal into the appropriate location for
>>  the aggregate, rather than trying to emit it as a temporary and
>>  memcpy() it.
>> 
>> Fixes PR10138 / <rdar://problem/9615901>.
>> 
>> 
>> Added:
>>    cfe/trunk/test/CodeGenCXX/compound-literals.cpp   (with props)
>> Modified:
>>    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
>>    cfe/trunk/lib/Sema/SemaExpr.cpp
>> 
>> Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=133235&r1=133234&r2=133235&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Jun 16 23:59:12 2011
>> @@ -91,9 +91,7 @@
>>   void VisitMemberExpr(MemberExpr *ME) { EmitAggLoadOfLValue(ME); }
>>   void VisitUnaryDeref(UnaryOperator *E) { EmitAggLoadOfLValue(E); }
>>   void VisitStringLiteral(StringLiteral *E) { EmitAggLoadOfLValue(E); }
>> -  void VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
>> -    EmitAggLoadOfLValue(E);
>> -  }
>> +  void VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
>>   void VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
>>     EmitAggLoadOfLValue(E);
>>   }
>> @@ -247,6 +245,13 @@
>>   EmitFinalDestCopy(e, CGF.getOpaqueLValueMapping(e));
>>  }
>> 
>> +void
>> +AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
>> +  AggValueSlot Slot = EnsureSlot(E->getType());
>> +  CGF.EmitAggExpr(E->getInitializer(), Slot);
>> +}
>> +
> 
> Does this work properly with code like the following?
> 
> typedef struct S { int x,y; } S;
> S x(struct S s) { s = (S){s.y,s.x}; return s; }

Nice catch! I've papered over the problem in r133261 (in the same way that we papered over it previously), but, as I've noted in that commit, I'm suspicious of the aggregate-assignment code.

	- Doug



More information about the cfe-commits mailing list