[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
This revision was automatically updated to reflect the committed changes. Closed by commit rL304470: [CGDebugInfo] Finalize SubPrograms when we're done with them (authored by kfischer). Changed prior to commit: https://reviews.llvm.org/D33705?vs=101092=101107#toc Repository: rL LLVM https://reviews.llvm.org/D33705 Files: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -3263,7 +3263,7 @@ void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) { assert(CurInlinedAt && "unbalanced inline scope stack"); - EmitFunctionEnd(Builder); + EmitFunctionEnd(Builder, nullptr); setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } @@ -3332,7 +3332,7 @@ LexicalBlockStack.pop_back(); } -void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) { +void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) { assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); unsigned RCount = FnBeginRegionCount.back(); assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch"); @@ -3344,6 +3344,9 @@ LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); + + if (Fn && Fn->getSubprogram()) +DBuilder.finalizeSubprogram(Fn->getSubprogram()); } llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h === --- cfe/trunk/lib/CodeGen/CGDebugInfo.h +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h @@ -367,7 +367,7 @@ void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType); /// Constructs the debug code for exiting a function. - void EmitFunctionEnd(CGBuilderTy ); + void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn); /// Emit metadata to indicate the beginning of a new lexical block /// and push the block onto the stack. Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -348,7 +348,7 @@ // Emit debug descriptor for function end. if (CGDebugInfo *DI = getDebugInfo()) -DI->EmitFunctionEnd(Builder); +DI->EmitFunctionEnd(Builder, CurFn); // Reset the debug location to that of the simple 'return' expression, if any // rather than that of the end of the function's scope '}'. Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -3263,7 +3263,7 @@ void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) { assert(CurInlinedAt && "unbalanced inline scope stack"); - EmitFunctionEnd(Builder); + EmitFunctionEnd(Builder, nullptr); setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } @@ -3332,7 +3332,7 @@ LexicalBlockStack.pop_back(); } -void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) { +void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) { assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); unsigned RCount = FnBeginRegionCount.back(); assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch"); @@ -3344,6 +3344,9 @@ LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); + + if (Fn && Fn->getSubprogram()) +DBuilder.finalizeSubprogram(Fn->getSubprogram()); } llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h === --- cfe/trunk/lib/CodeGen/CGDebugInfo.h +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h @@ -367,7 +367,7 @@ void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType); /// Constructs the debug code for exiting a function. - void EmitFunctionEnd(CGBuilderTy ); + void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn); /// Emit metadata to indicate the beginning of a new lexical block /// and push the block onto the stack. Index: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp @@ -348,7 +348,7 @@ // Emit debug descriptor for function end. if (CGDebugInfo *DI = getDebugInfo()) -DI->EmitFunctionEnd(Builder); +DI->EmitFunctionEnd(Builder, CurFn); // Reset the debug location to that of the simple 'return' expression, if any // rather than that of the end of the function's scope '}'. ___ cfe-commits mailing list
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
loladiro added a comment. I don't think that change is entirely necessary. I don't have any strong objections to it, but I also don't see a good reason to require it. In any case, let me get this in to be able to re-land https://reviews.llvm.org/D33655 and we can revisit the more disruptive change later. https://reviews.llvm.org/D33705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
aprantl added a comment. Looks good.. Are you also planning to change DIBuilder to not finalize subprograms automatically any more (and not insert them into AllSubprograms)? (That will be the more impactful change as it will force all non-clang frontends to make a similar change). https://reviews.llvm.org/D33705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
loladiro added a comment. There's already such a test case, but the cloning currently doesn't assert properly (but it can generate incorrect code). https://reviews.llvm.org/D33655 fixes that up, so I think the testing is covered once that LLVM commit goes in. I'll hold off a little while to give @aprantl a chance to look at this as well, but I do want to get this in in short order, so I can recommit https://reviews.llvm.org/D33655. https://reviews.llvm.org/D33705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
dblaikie accepted this revision. dblaikie added a comment. This revision is now accepted and ready to land. I guess this would need a cross-project test case (ie: it'd have to run LLVM optimizations to fail/pass/demonstrate the fix). I think it'd be OK to add one if there's a neat/clean/obvious optimization that can be reliably triggered to do the cloning that would assert/crash - please add one if you think that's practical/reasonable. https://reviews.llvm.org/D33705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
loladiro added a comment. @aprantl @dblaikie See if you like this better. https://reviews.llvm.org/D33705 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
loladiro updated this revision to Diff 101092. loladiro added a comment. Finalize all subprograms when we're done emitting them. The one we're interested in is a side effect, but doing this uniformly might be cleaner and help avoid similar errors in the future. https://reviews.llvm.org/D33705 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h lib/CodeGen/CodeGenFunction.cpp Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -348,7 +348,7 @@ // Emit debug descriptor for function end. if (CGDebugInfo *DI = getDebugInfo()) -DI->EmitFunctionEnd(Builder); +DI->EmitFunctionEnd(Builder, CurFn); // Reset the debug location to that of the simple 'return' expression, if any // rather than that of the end of the function's scope '}'. Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -367,7 +367,7 @@ void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType); /// Constructs the debug code for exiting a function. - void EmitFunctionEnd(CGBuilderTy ); + void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn); /// Emit metadata to indicate the beginning of a new lexical block /// and push the block onto the stack. Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -3263,7 +3263,7 @@ void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) { assert(CurInlinedAt && "unbalanced inline scope stack"); - EmitFunctionEnd(Builder); + EmitFunctionEnd(Builder, nullptr); setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } @@ -3332,7 +3332,7 @@ LexicalBlockStack.pop_back(); } -void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) { +void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) { assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); unsigned RCount = FnBeginRegionCount.back(); assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch"); @@ -3344,6 +3344,9 @@ LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); + + if (Fn && Fn->getSubprogram()) +DBuilder.finalizeSubprogram(Fn->getSubprogram()); } llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, Index: lib/CodeGen/CodeGenFunction.cpp === --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -348,7 +348,7 @@ // Emit debug descriptor for function end. if (CGDebugInfo *DI = getDebugInfo()) -DI->EmitFunctionEnd(Builder); +DI->EmitFunctionEnd(Builder, CurFn); // Reset the debug location to that of the simple 'return' expression, if any // rather than that of the end of the function's scope '}'. Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -367,7 +367,7 @@ void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType); /// Constructs the debug code for exiting a function. - void EmitFunctionEnd(CGBuilderTy ); + void EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn); /// Emit metadata to indicate the beginning of a new lexical block /// and push the block onto the stack. Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -3263,7 +3263,7 @@ void CGDebugInfo::EmitInlineFunctionEnd(CGBuilderTy ) { assert(CurInlinedAt && "unbalanced inline scope stack"); - EmitFunctionEnd(Builder); + EmitFunctionEnd(Builder, nullptr); setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } @@ -3332,7 +3332,7 @@ LexicalBlockStack.pop_back(); } -void CGDebugInfo::EmitFunctionEnd(CGBuilderTy ) { +void CGDebugInfo::EmitFunctionEnd(CGBuilderTy , llvm::Function *Fn) { assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); unsigned RCount = FnBeginRegionCount.back(); assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch"); @@ -3344,6 +3344,9 @@ LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); + + if (Fn && Fn->getSubprogram()) +DBuilder.finalizeSubprogram(Fn->getSubprogram()); } llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
For some reason your comments aren't showing up on Phabricator, so replying via email - hope everybody sees it. If SPs are now all finalized early - I'm assuming there's some other code > that finalizes SPs that's no longer needed? > Not all of them, just the one before cloning. I wanted to make the minimal change possible here, since this already seems like a bit of a hack to work around the fact that we can't properly forward variadic function calls at the IR level. > Also - this seems like a layering/separation issue - does other code call > into the DI as casually/explicitly as this code being added to CGVTables? > (Or should the callback go through some more generic entry point in > CGDebugInfo to delegate/handle that?) & is there nothing in CGDebugInfo > that is already called back in a timely fashion to handle this? I'm > guessing what's needed is a "IR has finished being generated for this > function, opt/codegen is about to start"? That seems like a good generic > callback & probably shouldn't be coming from something called CGVTables? > (presuming there's a more general place to put that) > I suppose there's CGDebugInfo::EmitFunctionEnd, so if we did want to finalize every SP as soon as we're done with it, we could put an explicit call to that extent there. Frankly though I don't really know the clang code too well, I just want to unbreak LLVM ;). ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
I'll let Adrian weigh in - but I suspect, if possible, it'd be better to just finalize them all once IRGen for the function finishes. On Tue, May 30, 2017 at 6:02 PM Keno Fischerwrote: > For some reason your comments aren't showing up on Phabricator, so > replying via email - hope everybody sees it. > > If SPs are now all finalized early - I'm assuming there's some other code >> that finalizes SPs that's no longer needed? >> > > Not all of them, just the one before cloning. I wanted to make the minimal > change possible here, since this already seems like a bit of a hack to work > around the fact that we can't properly forward variadic function calls at > the IR level. > > >> Also - this seems like a layering/separation issue - does other code call >> into the DI as casually/explicitly as this code being added to CGVTables? >> (Or should the callback go through some more generic entry point in >> CGDebugInfo to delegate/handle that?) & is there nothing in CGDebugInfo >> that is already called back in a timely fashion to handle this? I'm >> guessing what's needed is a "IR has finished being generated for this >> function, opt/codegen is about to start"? That seems like a good generic >> callback & probably shouldn't be coming from something called CGVTables? >> (presuming there's a more general place to put that) >> > > I suppose there's CGDebugInfo::EmitFunctionEnd, so if we did want to > finalize every SP as soon as we're done with it, we could put an explicit > call to that extent there. Frankly though I don't really know the clang > code too well, I just want to unbreak LLVM ;). > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
If SPs are now all finalized early - I'm assuming there's some other code that finalizes SPs that's no longer needed? Also - this seems like a layering/separation issue - does other code call into the DI as casually/explicitly as this code being added to CGVTables? (Or should the callback go through some more generic entry point in CGDebugInfo to delegate/handle that?) & is there nothing in CGDebugInfo that is already called back in a timely fashion to handle this? I'm guessing what's needed is a "IR has finished being generated for this function, opt/codegen is about to start"? That seems like a good generic callback & probably shouldn't be coming from something called CGVTables? (presuming there's a more general place to put that) On Tue, May 30, 2017 at 5:30 PM Keno Fischer via Phabricator < revi...@reviews.llvm.org> wrote: > loladiro created this revision. > > LLVM commit https://reviews.llvm.org/D33655 was reverted, because it > exposed an assertion failure, > in `GenerateVarArgsThunk`. That function attempts to clone a function > before clang is entirely done generating the debug info for the current > compliation unit. That is not a valid use of the API, because it expects > that there are no temporary MD nodes in the nodes that it needs to clone. > However, until now, this did not cause any problems (though could have > caused assertions in the backend due to mismatched debug info metadata). > > Attempt to rectify this by finalizing the SP before attempting to clone it. > The requisite LLVM API is being introduced in > https://reviews.llvm.org/D33704. > > > https://reviews.llvm.org/D33705 > > Files: > lib/CodeGen/CGDebugInfo.h > lib/CodeGen/CGVTables.cpp > > > Index: lib/CodeGen/CGVTables.cpp > === > --- lib/CodeGen/CGVTables.cpp > +++ lib/CodeGen/CGVTables.cpp > @@ -152,6 +152,12 @@ >llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); >llvm::Function *BaseFn = cast(Callee); > > + // We may not clone a subprogram that contains temporary metadata, so > finalize > + // it now - we will not be modifying it. > + if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) > +if (llvm::DISubprogram *SP = BaseFn->getSubprogram()) > + DI->finalizeSP(SP); > + >// Clone to thunk. >llvm::ValueToValueMapTy VMap; >llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap); > Index: lib/CodeGen/CGDebugInfo.h > === > --- lib/CodeGen/CGDebugInfo.h > +++ lib/CodeGen/CGDebugInfo.h > @@ -308,6 +308,7 @@ >~CGDebugInfo(); > >void finalize(); > + void finalizeSP(llvm::DISubprogram *SP) { DBuilder.finalizeSP(SP); } > >/// Module debugging: Support for building PCMs. >/// @{ > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D33705: [CGVTables] Finalize SP before attempting to clone it
loladiro created this revision. LLVM commit https://reviews.llvm.org/D33655 was reverted, because it exposed an assertion failure, in `GenerateVarArgsThunk`. That function attempts to clone a function before clang is entirely done generating the debug info for the current compliation unit. That is not a valid use of the API, because it expects that there are no temporary MD nodes in the nodes that it needs to clone. However, until now, this did not cause any problems (though could have caused assertions in the backend due to mismatched debug info metadata). Attempt to rectify this by finalizing the SP before attempting to clone it. The requisite LLVM API is being introduced in https://reviews.llvm.org/D33704. https://reviews.llvm.org/D33705 Files: lib/CodeGen/CGDebugInfo.h lib/CodeGen/CGVTables.cpp Index: lib/CodeGen/CGVTables.cpp === --- lib/CodeGen/CGVTables.cpp +++ lib/CodeGen/CGVTables.cpp @@ -152,6 +152,12 @@ llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); llvm::Function *BaseFn = cast(Callee); + // We may not clone a subprogram that contains temporary metadata, so finalize + // it now - we will not be modifying it. + if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) +if (llvm::DISubprogram *SP = BaseFn->getSubprogram()) + DI->finalizeSP(SP); + // Clone to thunk. llvm::ValueToValueMapTy VMap; llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap); Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -308,6 +308,7 @@ ~CGDebugInfo(); void finalize(); + void finalizeSP(llvm::DISubprogram *SP) { DBuilder.finalizeSP(SP); } /// Module debugging: Support for building PCMs. /// @{ Index: lib/CodeGen/CGVTables.cpp === --- lib/CodeGen/CGVTables.cpp +++ lib/CodeGen/CGVTables.cpp @@ -152,6 +152,12 @@ llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); llvm::Function *BaseFn = cast(Callee); + // We may not clone a subprogram that contains temporary metadata, so finalize + // it now - we will not be modifying it. + if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) +if (llvm::DISubprogram *SP = BaseFn->getSubprogram()) + DI->finalizeSP(SP); + // Clone to thunk. llvm::ValueToValueMapTy VMap; llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap); Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -308,6 +308,7 @@ ~CGDebugInfo(); void finalize(); + void finalizeSP(llvm::DISubprogram *SP) { DBuilder.finalizeSP(SP); } /// Module debugging: Support for building PCMs. /// @{ ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits