<div dir="ltr">This code ultimately went away in r232731 and we took a new approach in r232788.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 6, 2015 at 12:08 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">> On Feb 26, 2015, at 12:08 PM, John McCall <<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>> wrote:<br>
><br>
>> On Feb 25, 2015, at 3:48 PM, Larisse Voufo <<a href="mailto:lvoufo@google.com">lvoufo@google.com</a>> wrote:<br>
>> Author: lvoufo<br>
>> Date: Wed Feb 25 17:48:43 2015<br>
>> New Revision: 230580<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=230580&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=230580&view=rev</a><br>
>> Log:<br>
>> Improvement on sized deallocation from r230160:<br>
>> Do not declare sized deallocation functions dependently on whether it is found in global scope. Instead, enforce the branching in emitted code by (1) declaring the functions extern_weak and (2) emitting sized delete expressions as a branching between both forms delete.<br>
>><br>
>> Modified:<br>
>>   cfe/trunk/lib/CodeGen/CGExprCXX.cpp<br>
>>   cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
>>   cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp<br>
>>   cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp<br>
>>   cfe/trunk/test/CodeGenCXX/pr21754.cpp<br>
>><br>
>> Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=230580&r1=230579&r2=230580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=230580&r1=230579&r2=230580&view=diff</a><br>
>> ==============================================================================<br>
>> --- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)<br>
>> +++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Feb 25 17:48:43 2015<br>
>> @@ -1422,6 +1422,71 @@ CodeGenFunction::pushCallObjectDeleteCle<br>
>>                                        OperatorDelete, ElementType);<br>
>> }<br>
>><br>
>> +static void EmitDelete(CodeGenFunction &CGF,<br>
>> +                              const CXXDeleteExpr *DE,<br>
>> +                              llvm::Value *Ptr,<br>
>> +                              QualType ElementType);<br>
>> +<br>
>> +static void EmitSizedDelete(CodeGenFunction &CGF,<br>
>> +                            const CXXDeleteExpr *DE,<br>
>> +                            llvm::Value *Ptr,<br>
>> +                            QualType ElementType,<br>
>> +                            FunctionDecl* UnsizedDealloc) {<br>
>> +<br>
>> +  if (CGF.getLangOpts().DefineSizedDeallocation) {<br>
>> +    // The delete operator in use is fixed. So simply emit the delete expr.<br>
>> +    EmitDelete(CGF, DE, Ptr, ElementType);<br>
>> +    return;<br>
>> +  }<br>
>> +<br>
>> +  assert(UnsizedDealloc && "We must be emiting a 'sized' delete expr");<br>
>> +<br>
>> +  // Branch off over the value of operator delete:<br>
>> +  // Use the sized form if available, and default on the unsized form otherwise.<br>
>> +  llvm::BasicBlock *ThenBlock = CGF.createBasicBlock("if.then");<br>
>> +  llvm::BasicBlock *ContBlock = CGF.createBasicBlock("if.end");<br>
>> +  llvm::BasicBlock *ElseBlock = CGF.createBasicBlock("if.else");<br>
>> +<br>
>> +  // Emit the condition.<br>
>> +  const FunctionDecl *OpDelFD = DE->getOperatorDelete();<br>
>> +  llvm::Value *OpDelAddr = CGF.CGM.GetAddrOfFunction(OpDelFD);<br>
>> +  //llvm::Function *OpDel = dyn_cast<llvm::Function>(OpDelAddr);<br>
>> +  llvm::Value *SDE = CGF.Builder.CreateIsNotNull(OpDelAddr, "sized.del.exists");<br>
>> +  CGF.Builder.CreateCondBr(SDE, ThenBlock, ElseBlock);<br>
>> +<br>
>> +  // Emit the 'then' code.<br>
>> +  CGF.EmitBlock(ThenBlock);<br>
>> +  EmitDelete(CGF, DE, Ptr, ElementType);<br>
>> +  CGF.EmitBranch(ContBlock);<br>
>> +<br>
>> +  // Compute the 'unsized' delete expr.<br>
>> +  CXXDeleteExpr * E = const_cast<CXXDeleteExpr*>(DE);<br>
>> +  CXXDeleteExpr *UnsizedDE =<br>
>> +  new (CGF.getContext()) CXXDeleteExpr(CGF.getContext().VoidTy,<br>
>> +                                       E->isGlobalDelete(),<br>
>> +                                       E->isArrayForm(),<br>
>> +                                       E->isArrayFormAsWritten(),<br>
>> +                                       E->doesUsualArrayDeleteWantSize(),<br>
>> +                                       UnsizedDealloc,<br>
>> +                                       E->getArgument(),<br>
>> +                                       E->getLocStart());<br>
><br>
> Instead of doing it this way, please introduce a common function to call<br>
> from EmitDeleteCall and the CallArrayDelete cleanup.<br>
><br>
> Doing it this way unnecessarily clones the object / array destruction code,<br>
> causes a useless branch when making a virtual call to the deleting destructor,<br>
> and fails to branch appropriately within a deleting destructor.<br>
><br>
> The common function will also be a natural place in the future to check the<br>
> language that elides the dynamic check and assumes that the sized<br>
> deallocation function exists.  (The reverse option will be implemented by<br>
> having Sema just specify an unsized deallocation function.)<br>
<br>
</div></div>Ping.<br>
<div class="HOEnZb"><div class="h5"><br>
John.<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>