<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 27, 2015 at 10:38 AM, Adrian Prantl <span dir="ltr"><<a href="mailto:aprantl@apple.com" target="_blank">aprantl@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"><br>
> On Jan 13, 2015, at 11:38 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
> Author: dblaikie<br>
> Date: Wed Jan 14 01:38:27 2015<br>
> New Revision: 225956<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=225956&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=225956&view=rev</a><br>
> Log:<br>
> Reapply r225000 (reverted in r225555): DebugInfo: Generalize debug info location handling (and follow-up commits).<br>
><br>
> Several pieces of code were relying on implicit debug location setting<br>
> which usually lead to incorrect line information anyway. So I've fixed<br>
> those (in r225955 and r225845) separately which should pave the way for<br>
> this commit to be cleanly reapplied.<br>
><br>
> The reason these implicit dependencies resulted in crashes with this<br>
> patch is that the debug location would no longer implicitly leak from<br>
> one place to another, but be set back to invalid. Once a call with<br>
> no/invalid location was emitted, if that call was ever inlined it could<br>
> produce invalid debugloc chains and assert during LLVM's codegen.<br>
><br>
> There may be further cases of such bugs in this patch - they're hard to<br>
> flush out with regression testing, so I'll keep an eye out for reports<br>
> and investigate/fix them ASAP if they come up.<br>
><br>
> Original commit message:<br>
><br>
> Reapply "DebugInfo: Generalize debug info location handling"<br>
><br>
> Originally committed in r224385 and reverted in r224441 due to concerns<br>
> this change might've introduced a crash. Turns out this change fixes the<br>
> crash introduced by one of my earlier more specific location handling<br>
> changes (those specific fixes are reverted by this patch, in favor of<br>
> the more general solution).<br>
><br>
> Recommitted in r224941 and reverted in r224970 after it caused a crash<br>
> when building compiler-rt. Looks to be due to this change zeroing out<br>
> the debug location when emitting default arguments (which were meant to<br>
> inherit their outer expression's location) thus creating call<br>
> instructions without locations - these create problems for inlining and<br>
> must not be created. That is fixed and tested in this version of the<br>
> change.<br>
><br>
> Original commit message:<br>
><br>
> This is a more scalable (fixed in mostly one place, rather than many<br>
> places that will need constant improvement/maintenance) solution to<br>
> several commits I've made recently to increase source fidelity for<br>
> subexpressions.<br>
><br>
> This resetting had to be done at the DebugLoc level (not the<br>
> SourceLocation level) to preserve scoping information (if the resetting<br>
> was done with CGDebugInfo::EmitLocation, it would've caused the tail end<br>
> of an expression's codegen to end up in a potentially different scope<br>
> than the start, even though it was at the same source location). The<br>
> drawback to this is that it might leave CGDebugInfo out of sync. Ideally<br>
> CGDebugInfo shouldn't have a duplicate sense of the current<br>
> SourceLocation, but for now it seems it does... - I don't think I'm<br>
> going to tackle removing that just now.<br>
><br>
> I expect this'll probably cause some more buildbot fallout & I'll<br>
> investigate that as it comes up.<br>
><br>
> Also these sort of improvements might be starting to show a weakness/bug<br>
> in LLVM's line table handling: we don't correctly emit is_stmt for<br>
> statements, we just put it on every line table entry. This means one<br>
> statement split over multiple lines appears as multiple 'statements' and<br>
> two statements on one line (without column info) are treated as one<br>
> statement.<br>
><br>
> I don't think we have any IR representation of statements that would<br>
> help us distinguish these cases and identify the beginning of each<br>
> statement - so that might be something we need to add (possibly to the<br>
> lexical scope chain - a scope for each statement). This does cause some<br>
> problems for GDB and possibly other DWARF consumers.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/CodeGen/CGBlocks.cpp<br>
>    cfe/trunk/lib/CodeGen/CGClass.cpp<br>
>    cfe/trunk/lib/CodeGen/CGCleanup.cpp<br>
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
>    cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
>    cfe/trunk/lib/CodeGen/CGDecl.cpp<br>
>    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
>    cfe/trunk/lib/CodeGen/CGException.cpp<br>
>    cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
>    cfe/trunk/lib/CodeGen/CGExprCXX.cpp<br>
>    cfe/trunk/lib/CodeGen/CGExprComplex.cpp<br>
>    cfe/trunk/lib/CodeGen/CGExprScalar.cpp<br>
>    cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
>    cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp<br>
>    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
>    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
>    cfe/trunk/test/CodeGenCXX/PR20038.cpp<br>
>    cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
>    cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -875,7 +875,7 @@ llvm::Value *CodeGenFunction::EmitBlockL<br>
>       // locations of subexpressions in the initialization.<br>
>       EmitExprAsInit(&l2r, &blockFieldPseudoVar,<br>
>                      MakeAddrLValue(blockField, type, align),<br>
> -                     /*captured by init*/ false, SourceLocation());<br>
> +                     /*captured by init*/ false);<br>
>     }<br>
><br>
>     // Activate the cleanup if layout pushed one.<br>
> @@ -1178,7 +1178,7 @@ CodeGenFunction::GenerateBlockFunction(G<br>
>     Alloca->setAlignment(Align);<br>
>     // Set the DebugLocation to empty, so the store is recognized as a<br>
>     // frame setup instruction by llvm::DwarfDebug::beginFunction().<br>
> -    NoLocation NL(*this, Builder);<br>
> +    ApplyDebugLocation NL(*this);<br>
>     Builder.CreateAlignedStore(BlockPointer, Alloca, Align);<br>
>     BlockPointerDbgLoc = Alloca;<br>
>   }<br>
> @@ -1329,9 +1329,9 @@ CodeGenFunction::GenerateCopyHelperFunct<br>
>                                           false,<br>
>                                           false);<br>
>   // Create a scope with an artificial location for the body of this function.<br>
> -  ArtificialLocation AL(*this, Builder);<br>
> +  ApplyDebugLocation NL(*this);<br>
>   StartFunction(FD, C.VoidTy, Fn, FI, args);<br>
> -  AL.Emit();<br>
> +  ArtificialLocation AL(*this);<br>
><br>
>   llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();<br>
><br>
> @@ -1500,9 +1500,9 @@ CodeGenFunction::GenerateDestroyHelperFu<br>
>                                           nullptr, SC_Static,<br>
>                                           false, false);<br>
>   // Create a scope with an artificial location for the body of this function.<br>
> -  ArtificialLocation AL(*this, Builder);<br>
> +  ApplyDebugLocation NL(*this);<br>
>   StartFunction(FD, C.VoidTy, Fn, FI, args);<br>
> -  AL.Emit();<br>
> +  ArtificialLocation AL(*this);<br>
><br>
>   llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGClass.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -544,6 +544,7 @@ static void EmitMemberInitializer(CodeGe<br>
>                                   CXXCtorInitializer *MemberInit,<br>
>                                   const CXXConstructorDecl *Constructor,<br>
>                                   FunctionArgList &Args) {<br>
> +  ApplyDebugLocation Loc(CGF, MemberInit->getMemberLocation());<br>
>   assert(MemberInit->isAnyMemberInitializer() &&<br>
>          "Must have member initializer!");<br>
>   assert(MemberInit->getInit() && "Must have initializer!");<br>
> @@ -597,26 +598,25 @@ static void EmitMemberInitializer(CodeGe<br>
>   ArrayRef<VarDecl *> ArrayIndexes;<br>
>   if (MemberInit->getNumArrayIndices())<br>
>     ArrayIndexes = MemberInit->getArrayIndexes();<br>
> -  CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes,<br>
> -                              MemberInit->getMemberLocation());<br>
> +  ApplyDebugLocation DL(CGF, MemberInit->getMemberLocation());<br>
> +  CGF.EmitInitializerForField(Field, LHS, MemberInit->getInit(), ArrayIndexes);<br>
> }<br>
><br>
> -void CodeGenFunction::EmitInitializerForField(FieldDecl *Field, LValue LHS,<br>
> -                                              Expr *Init,<br>
> -                                              ArrayRef<VarDecl *> ArrayIndexes,<br>
> -                                              SourceLocation DbgLoc) {<br>
> +void CodeGenFunction::EmitInitializerForField(<br>
> +    FieldDecl *Field, LValue LHS, Expr *Init,<br>
> +    ArrayRef<VarDecl *> ArrayIndexes) {<br>
>   QualType FieldType = Field->getType();<br>
>   switch (getEvaluationKind(FieldType)) {<br>
>   case TEK_Scalar:<br>
>     if (LHS.isSimple()) {<br>
> -      EmitExprAsInit(Init, Field, LHS, false, DbgLoc);<br>
> +      EmitExprAsInit(Init, Field, LHS, false);<br>
>     } else {<br>
>       RValue RHS = RValue::get(EmitScalarExpr(Init));<br>
>       EmitStoreThroughLValue(RHS, LHS);<br>
>     }<br>
>     break;<br>
>   case TEK_Complex:<br>
> -    EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true, DbgLoc);<br>
> +    EmitComplexExprIntoLValue(Init, LHS, /*isInit*/ true);<br>
>     break;<br>
>   case TEK_Aggregate: {<br>
>     llvm::Value *ArrayIndexVar = nullptr;<br>
> @@ -783,8 +783,6 @@ void CodeGenFunction::EmitConstructorBod<br>
>   // delegation optimization.<br>
>   if (CtorType == Ctor_Complete && IsConstructorDelegationValid(Ctor) &&<br>
>       CGM.getTarget().getCXXABI().hasConstructorVariants()) {<br>
> -    if (CGDebugInfo *DI = getDebugInfo())<br>
> -      DI->EmitLocation(Builder, Ctor->getLocEnd());<br>
>     EmitDelegateCXXConstructorCall(Ctor, Ctor_Base, Args, Ctor->getLocEnd());<br>
>     return;<br>
>   }<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -861,10 +861,7 @@ void CodeGenFunction::PopCleanupBlock(bo<br>
><br>
>   // Emit the EH cleanup if required.<br>
>   if (RequiresEHCleanup) {<br>
> -    CGDebugInfo *DI = getDebugInfo();<br>
> -    SaveAndRestoreLocation AutoRestoreLocation(*this, Builder);<br>
> -    if (DI)<br>
> -      DI->EmitLocation(Builder, CurEHLocation);<br>
> +    ApplyDebugLocation AutoRestoreLocation(*this, CurEHLocation);<br>
><br>
>     CGBuilderTy::InsertPoint SavedIP = Builder.saveAndClearIP();<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -52,54 +52,47 @@ CGDebugInfo::~CGDebugInfo() {<br>
>          "Region stack mismatch, stack not empty!");<br>
> }<br>
><br>
> -SaveAndRestoreLocation::SaveAndRestoreLocation(CodeGenFunction &CGF,<br>
> -                                               CGBuilderTy &B)<br>
> -    : DI(CGF.getDebugInfo()), Builder(B) {<br>
> -  if (DI) {<br>
> -    SavedLoc = DI->getLocation();<br>
> -    DI->CurLoc = SourceLocation();<br>
> +ArtificialLocation::ArtificialLocation(CodeGenFunction &CGF)<br>
> +    : ApplyDebugLocation(CGF) {<br>
> +  if (auto *DI = CGF.getDebugInfo()) {<br>
> +    // Construct a location that has a valid scope, but no line info.<br>
> +    assert(!DI->LexicalBlockStack.empty());<br>
> +    llvm::DIDescriptor Scope(DI->LexicalBlockStack.back());<br>
> +    CGF.Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(0, 0, Scope));<br>
>   }<br>
> }<br>
><br>
> -SaveAndRestoreLocation::~SaveAndRestoreLocation() {<br>
> -  if (DI)<br>
> -    DI->EmitLocation(Builder, SavedLoc);<br>
> -}<br>
> -<br>
> -NoLocation::NoLocation(CodeGenFunction &CGF, CGBuilderTy &B)<br>
> -    : SaveAndRestoreLocation(CGF, B) {<br>
> -  if (DI)<br>
> -    Builder.SetCurrentDebugLocation(llvm::DebugLoc());<br>
> -}<br>
> -<br>
> -NoLocation::~NoLocation() {<br>
> -  if (DI)<br>
> -    assert(Builder.getCurrentDebugLocation().isUnknown());<br>
> -}<br>
> -<br>
> -ArtificialLocation::ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B)<br>
> -    : SaveAndRestoreLocation(CGF, B) {<br>
> -  if (DI)<br>
> -    Builder.SetCurrentDebugLocation(llvm::DebugLoc());<br>
> +ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,<br>
> +                                       SourceLocation TemporaryLocation,<br>
> +                                       bool ForceColumnInfo)<br>
> +    : CGF(CGF) {<br>
> +  if (auto *DI = CGF.getDebugInfo()) {<br>
> +    OriginalLocation = CGF.Builder.getCurrentDebugLocation();<br>
> +    if (TemporaryLocation.isInvalid())<br>
> +      CGF.Builder.SetCurrentDebugLocation(llvm::DebugLoc());<br>
> +    else<br>
> +      DI->EmitLocation(CGF.Builder, TemporaryLocation, ForceColumnInfo);<br>
> +  }<br>
> }<br>
><br>
> -void ArtificialLocation::Emit() {<br>
> -  if (DI) {<br>
> -    // Sync the Builder.<br>
> -    DI->EmitLocation(Builder, SavedLoc);<br>
> -    DI->CurLoc = SourceLocation();<br>
> -    // Construct a location that has a valid scope, but no line info.<br>
> -    assert(!DI->LexicalBlockStack.empty());<br>
> -    llvm::DIDescriptor Scope(DI->LexicalBlockStack.back());<br>
> -    Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(0, 0, Scope));<br>
> +ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc)<br>
> +    : CGF(CGF) {<br>
> +  if (CGF.getDebugInfo()) {<br>
> +    OriginalLocation = CGF.Builder.getCurrentDebugLocation();<br>
> +    if (!Loc.isUnknown())<br>
> +      CGF.Builder.SetCurrentDebugLocation(Loc);<br>
>   }<br>
> }<br>
><br>
> -ArtificialLocation::~ArtificialLocation() {<br>
> -  if (DI)<br>
> -    assert(Builder.getCurrentDebugLocation().getLine() == 0);<br>
> +ApplyDebugLocation::~ApplyDebugLocation() {<br>
> +  // Query CGF so the location isn't overwritten when location updates are<br>
> +  // temporarily disabled (for C++ default function arguments)<br>
> +  if (CGF.getDebugInfo())<br>
> +    CGF.Builder.SetCurrentDebugLocation(OriginalLocation);<br>
> }<br>
><br>
> +/// ArtificialLocation - An RAII object that temporarily switches to<br>
> +/// an artificial debug location that has a valid scope, but no line<br>
> void CGDebugInfo::setLocation(SourceLocation Loc) {<br>
>   // If the new location isn't valid return.<br>
>   if (Loc.isInvalid())<br>
> @@ -2644,20 +2637,6 @@ void CGDebugInfo::EmitLocation(CGBuilder<br>
>   if (CurLoc.isInvalid() || CurLoc.isMacroID())<br>
>     return;<br>
><br>
> -  // Don't bother if things are the same as last time.<br>
> -  SourceManager &SM = CGM.getContext().getSourceManager();<br>
> -  assert(!LexicalBlockStack.empty());<br>
> -  if (CurLoc == PrevLoc ||<br>
> -      SM.getExpansionLoc(CurLoc) == SM.getExpansionLoc(PrevLoc))<br>
> -    // New Builder may not be in sync with CGDebugInfo.<br>
> -    if (!Builder.getCurrentDebugLocation().isUnknown() &&<br>
> -        Builder.getCurrentDebugLocation().getScope(CGM.getLLVMContext()) ==<br>
> -            LexicalBlockStack.back())<br>
> -      return;<br>
> -<br>
> -  // Update last state.<br>
> -  PrevLoc = CurLoc;<br>
> -<br>
>   llvm::MDNode *Scope = LexicalBlockStack.back();<br>
>   Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(<br>
>       getLineNumber(CurLoc), getColumnNumber(CurLoc, ForceColumnInfo), Scope));<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Wed Jan 14 01:38:27 2015<br>
> @@ -53,7 +53,7 @@ class CGDebugInfo {<br>
>   const CodeGenOptions::DebugInfoKind DebugKind;<br>
>   llvm::DIBuilder DBuilder;<br>
>   llvm::DICompileUnit TheCU;<br>
> -  SourceLocation CurLoc, PrevLoc;<br>
> +  SourceLocation CurLoc;<br>
>   llvm::DIType VTablePtrType;<br>
>   llvm::DIType ClassTy;<br>
>   llvm::DICompositeType ObjTy;<br>
> @@ -448,27 +448,17 @@ private:<br>
>   }<br>
> };<br>
><br>
> -/// SaveAndRestoreLocation - An RAII object saves the current location<br>
> -/// and automatically restores it to the original value.<br>
> -class SaveAndRestoreLocation {<br>
> +class ApplyDebugLocation {<br>
<br>
</div></div>I just noticed that ApplyDebugLocation has not doxygen comment that would explain how to use it. Would you like to write one up?<br></blockquote><div><br>Added a brief comment in r227356.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
thanks,<br>
adrian<br>
<div class="HOEnZb"><div class="h5"><br>
> protected:<br>
> -  SourceLocation SavedLoc;<br>
> -  CGDebugInfo *DI;<br>
> -  CGBuilderTy &Builder;<br>
> -public:<br>
> -  SaveAndRestoreLocation(CodeGenFunction &CGF, CGBuilderTy &B);<br>
> -  /// Autorestore everything back to normal.<br>
> -  ~SaveAndRestoreLocation();<br>
> -};<br>
> +  llvm::DebugLoc OriginalLocation;<br>
> +  CodeGenFunction &CGF;<br>
><br>
> -/// NoLocation - An RAII object that temporarily disables debug<br>
> -/// locations. This is useful for emitting instructions that should be<br>
> -/// counted towards the function prologue.<br>
> -class NoLocation : public SaveAndRestoreLocation {<br>
> public:<br>
> -  NoLocation(CodeGenFunction &CGF, CGBuilderTy &B);<br>
> -  /// Autorestore everything back to normal.<br>
> -  ~NoLocation();<br>
> +  ApplyDebugLocation(CodeGenFunction &CGF,<br>
> +                     SourceLocation TemporaryLocation = SourceLocation(),<br>
> +                     bool ForceColumnInfo = false);<br>
> +  ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);<br>
> +  ~ApplyDebugLocation();<br>
> };<br>
><br>
> /// ArtificialLocation - An RAII object that temporarily switches to<br>
> @@ -482,16 +472,9 @@ public:<br>
> /// This is necessary because passing an empty SourceLocation to<br>
> /// CGDebugInfo::setLocation() will result in the last valid location<br>
> /// being reused.<br>
> -class ArtificialLocation : public SaveAndRestoreLocation {<br>
> +class ArtificialLocation : public ApplyDebugLocation {<br>
> public:<br>
> -  ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B);<br>
> -<br>
> -  /// Set the current location to line 0, but within the current scope<br>
> -  /// (= the top of the LexicalBlockStack).<br>
> -  void Emit();<br>
> -<br>
> -  /// Autorestore everything back to normal.<br>
> -  ~ArtificialLocation();<br>
> +  ArtificialLocation(CodeGenFunction &CGF);<br>
> };<br>
><br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -600,14 +600,13 @@ static void drillIntoBlockVariable(CodeG<br>
> }<br>
><br>
> void CodeGenFunction::EmitScalarInit(const Expr *init, const ValueDecl *D,<br>
> -                                     LValue lvalue, bool capturedByInit,<br>
> -                                     SourceLocation DbgLoc) {<br>
> +                                     LValue lvalue, bool capturedByInit) {<br>
>   Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();<br>
>   if (!lifetime) {<br>
>     llvm::Value *value = EmitScalarExpr(init);<br>
>     if (capturedByInit)<br>
>       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));<br>
> -    EmitStoreThroughLValue(RValue::get(value), lvalue, true, DbgLoc);<br>
> +    EmitStoreThroughLValue(RValue::get(value), lvalue, true);<br>
>     return;<br>
>   }<br>
><br>
> @@ -1091,6 +1090,7 @@ void CodeGenFunction::EmitAutoVarInit(co<br>
>   if (emission.wasEmittedAsGlobal()) return;<br>
><br>
>   const VarDecl &D = *emission.Variable;<br>
> +  ApplyDebugLocation DL(*this, D.getLocation());<br>
>   QualType type = D.getType();<br>
><br>
>   // If this local has an initializer, emit it now.<br>
> @@ -1129,7 +1129,7 @@ void CodeGenFunction::EmitAutoVarInit(co<br>
>   if (!constant) {<br>
>     LValue lv = MakeAddrLValue(Loc, type, alignment);<br>
>     lv.setNonGC(true);<br>
> -    return EmitExprAsInit(Init, &D, lv, capturedByInit, D.getLocation());<br>
> +    return EmitExprAsInit(Init, &D, lv, capturedByInit);<br>
>   }<br>
><br>
>   if (!emission.IsConstantAggregate) {<br>
> @@ -1195,26 +1195,25 @@ void CodeGenFunction::EmitAutoVarInit(co<br>
> /// \param capturedByInit true if the variable is a __block variable<br>
> ///   whose address is potentially changed by the initializer<br>
> void CodeGenFunction::EmitExprAsInit(const Expr *init, const ValueDecl *D,<br>
> -                                     LValue lvalue, bool capturedByInit,<br>
> -                                     SourceLocation DbgLoc) {<br>
> +                                     LValue lvalue, bool capturedByInit) {<br>
>   QualType type = D->getType();<br>
><br>
>   if (type->isReferenceType()) {<br>
>     RValue rvalue = EmitReferenceBindingToExpr(init);<br>
>     if (capturedByInit)<br>
>       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));<br>
> -    EmitStoreThroughLValue(rvalue, lvalue, true, DbgLoc);<br>
> +    EmitStoreThroughLValue(rvalue, lvalue, true);<br>
>     return;<br>
>   }<br>
>   switch (getEvaluationKind(type)) {<br>
>   case TEK_Scalar:<br>
> -    EmitScalarInit(init, D, lvalue, capturedByInit, DbgLoc);<br>
> +    EmitScalarInit(init, D, lvalue, capturedByInit);<br>
>     return;<br>
>   case TEK_Complex: {<br>
>     ComplexPairTy complex = EmitComplexExpr(init);<br>
>     if (capturedByInit)<br>
>       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));<br>
> -    EmitStoreOfComplex(complex, lvalue, /*init*/ true, DbgLoc);<br>
> +    EmitStoreOfComplex(complex, lvalue, /*init*/ true);<br>
>     return;<br>
>   }<br>
>   case TEK_Aggregate:<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -469,11 +469,11 @@ CodeGenFunction::GenerateCXXGlobalInitFu<br>
>                                            ArrayRef<llvm::Function *> Decls,<br>
>                                            llvm::GlobalVariable *Guard) {<br>
>   {<br>
> -    ArtificialLocation AL(*this, Builder);<br>
> +    ApplyDebugLocation NL(*this);<br>
>     StartFunction(GlobalDecl(), getContext().VoidTy, Fn,<br>
>                   getTypes().arrangeNullaryFunction(), FunctionArgList());<br>
>     // Emit an artificial location for this function.<br>
> -    AL.Emit();<br>
> +    ArtificialLocation AL(*this);<br>
><br>
>     llvm::BasicBlock *ExitBlock = nullptr;<br>
>     if (Guard) {<br>
> @@ -520,11 +520,11 @@ void CodeGenFunction::GenerateCXXGlobalD<br>
>                   const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> ><br>
>                                                 &DtorsAndObjects) {<br>
>   {<br>
> -    ArtificialLocation AL(*this, Builder);<br>
> +    ApplyDebugLocation NL(*this);<br>
>     StartFunction(GlobalDecl(), getContext().VoidTy, Fn,<br>
>                   getTypes().arrangeNullaryFunction(), FunctionArgList());<br>
>     // Emit an artificial location for this function.<br>
> -    AL.Emit();<br>
> +    ArtificialLocation AL(*this);<br>
><br>
>     // Emit the dtors, in reverse order from construction.<br>
>     for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGException.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGException.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGException.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -734,9 +734,7 @@ llvm::BasicBlock *CodeGenFunction::EmitL<br>
><br>
>   // Save the current IR generation state.<br>
>   CGBuilderTy::InsertPoint savedIP = Builder.saveAndClearIP();<br>
> -  SaveAndRestoreLocation AutoRestoreLocation(*this, Builder);<br>
> -  if (CGDebugInfo *DI = getDebugInfo())<br>
> -    DI->EmitLocation(Builder, CurEHLocation);<br>
> +  ApplyDebugLocation AutoRestoreLocation(*this, CurEHLocation);<br>
><br>
>   const EHPersonality &personality = EHPersonality::get(CGM);<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -1438,11 +1438,7 @@ RValue CodeGenFunction::EmitLoadOfGlobal<br>
> /// lvalue, where both are guaranteed to the have the same type, and that type<br>
> /// is 'Ty'.<br>
> void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,<br>
> -                                             bool isInit,<br>
> -                                             SourceLocation DbgLoc) {<br>
> -  if (auto *DI = getDebugInfo())<br>
> -    DI->EmitLocation(Builder, DbgLoc);<br>
> -<br>
> +                                             bool isInit) {<br>
>   if (!Dst.isSimple()) {<br>
>     if (Dst.isVectorElt()) {<br>
>       // Read/modify/write the vector, inserting the new element.<br>
> @@ -2455,9 +2451,6 @@ LValue CodeGenFunction::EmitArraySubscri<br>
>     // The element count here is the total number of non-VLA elements.<br>
>     llvm::Value *numElements = getVLASize(vla).first;<br>
><br>
> -    if (auto *DI = getDebugInfo())<br>
> -      DI->EmitLocation(Builder, E->getLocStart());<br>
> -<br>
>     // Effectively, the multiply by the VLA size is part of the GEP.<br>
>     // GEP indexes are signed, and scaling an index isn't permitted to<br>
>     // signed-overflow, so we use the same semantics for our explicit<br>
> @@ -2503,9 +2496,6 @@ LValue CodeGenFunction::EmitArraySubscri<br>
>     // Propagate the alignment from the array itself to the result.<br>
>     ArrayAlignment = ArrayLV.getAlignment();<br>
><br>
> -    if (auto *DI = getDebugInfo())<br>
> -      DI->EmitLocation(Builder, E->getLocStart());<br>
> -<br>
>     if (getLangOpts().isSignedOverflowDefined())<br>
>       Address = Builder.CreateGEP(ArrayPtr, Args, "arrayidx");<br>
>     else<br>
> @@ -2513,8 +2503,6 @@ LValue CodeGenFunction::EmitArraySubscri<br>
>   } else {<br>
>     // The base must be a pointer, which is not an aggregate.  Emit it.<br>
>     llvm::Value *Base = EmitScalarExpr(E->getBase());<br>
> -    if (auto *DI = getDebugInfo())<br>
> -      DI->EmitLocation(Builder, E->getLocStart());<br>
>     if (getLangOpts().isSignedOverflowDefined())<br>
>       Address = Builder.CreateGEP(Base, Idx, "arrayidx");<br>
>     else<br>
> @@ -3071,18 +3059,15 @@ RValue CodeGenFunction::EmitRValueForFie<br>
><br>
> RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,<br>
>                                      ReturnValueSlot ReturnValue) {<br>
> -  if (CGDebugInfo *DI = getDebugInfo()) {<br>
> -    SourceLocation Loc = E->getLocStart();<br>
> -    // Force column info to be generated so we can differentiate<br>
> -    // multiple call sites on the same line in the debug info.<br>
> -    // FIXME: This is insufficient. Two calls coming from the same macro<br>
> -    // expansion will still get the same line/column and break debug info. It's<br>
> -    // possible that LLVM can be fixed to not rely on this uniqueness, at which<br>
> -    // point this workaround can be removed.<br>
> -    const FunctionDecl* Callee = E->getDirectCallee();<br>
> -    bool ForceColumnInfo = Callee && Callee->isInlineSpecified();<br>
> -    DI->EmitLocation(Builder, Loc, ForceColumnInfo);<br>
> -  }<br>
> +  // Force column info to be generated so we can differentiate<br>
> +  // multiple call sites on the same line in the debug info.<br>
> +  // FIXME: This is insufficient. Two calls coming from the same macro<br>
> +  // expansion will still get the same line/column and break debug info. It's<br>
> +  // possible that LLVM can be fixed to not rely on this uniqueness, at which<br>
> +  // point this workaround can be removed.<br>
> +  ApplyDebugLocation DL(*this, E->getLocStart(),<br>
> +                        E->getDirectCallee() &&<br>
> +                            E->getDirectCallee()->isInlineSpecified());<br>
><br>
>   // Builtins never have block type.<br>
>   if (E->getCallee()->getType()->isBlockPointerType())<br>
> @@ -3198,8 +3183,6 @@ LValue CodeGenFunction::EmitBinaryOperat<br>
><br>
>     RValue RV = EmitAnyExpr(E->getRHS());<br>
>     LValue LV = EmitCheckedLValue(E->getLHS(), TCK_Store);<br>
> -    if (CGDebugInfo *DI = getDebugInfo())<br>
> -      DI->EmitLocation(Builder, E->getLocStart());<br>
>     EmitStoreThroughLValue(RV, LV);<br>
>     return LV;<br>
>   }<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=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -187,8 +187,6 @@ RValue CodeGenFunction::EmitCXXMemberOrO<br>
>         unsigned ArgsToSkip = isa<CXXOperatorCallExpr>(CE) ? 1 : 0;<br>
>         llvm::Value *RHS =<br>
>             EmitLValue(*(CE->arg_begin() + ArgsToSkip)).getAddress();<br>
> -        if (auto *DI = getDebugInfo())<br>
> -          DI->EmitLocation(Builder, CE->getLocStart());<br>
>         EmitAggregateAssign(This, RHS, CE->getType());<br>
>         return RValue::get(This);<br>
>       }<br>
> @@ -754,15 +752,13 @@ static llvm::Value *EmitCXXNewAllocSize(<br>
> }<br>
><br>
> static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const Expr *Init,<br>
> -                                    QualType AllocType, llvm::Value *NewPtr,<br>
> -                                    SourceLocation DbgLoc = SourceLocation()) {<br>
> +                                    QualType AllocType, llvm::Value *NewPtr) {<br>
>   // FIXME: Refactor with EmitExprAsInit.<br>
>   CharUnits Alignment = CGF.getContext().getTypeAlignInChars(AllocType);<br>
>   switch (CGF.getEvaluationKind(AllocType)) {<br>
>   case TEK_Scalar:<br>
>     CGF.EmitScalarInit(Init, nullptr,<br>
> -                       CGF.MakeAddrLValue(NewPtr, AllocType, Alignment), false,<br>
> -                       DbgLoc);<br>
> +                       CGF.MakeAddrLValue(NewPtr, AllocType, Alignment), false);<br>
>     return;<br>
>   case TEK_Complex:<br>
>     CGF.EmitComplexExprIntoLValue(Init, CGF.MakeAddrLValue(NewPtr, AllocType,<br>
> @@ -1020,12 +1016,12 @@ static void EmitNewInitializer(CodeGenFu<br>
>                                llvm::Value *NewPtr,<br>
>                                llvm::Value *NumElements,<br>
>                                llvm::Value *AllocSizeWithoutCookie) {<br>
> +  ApplyDebugLocation DL(CGF, E->getStartLoc());<br>
>   if (E->isArray())<br>
>     CGF.EmitNewArrayInitializer(E, ElementType, NewPtr, NumElements,<br>
>                                 AllocSizeWithoutCookie);<br>
>   else if (const Expr *Init = E->getInitializer())<br>
> -    StoreAnyExprIntoOneUnit(CGF, Init, E->getAllocatedType(), NewPtr,<br>
> -                            E->getStartLoc());<br>
> +    StoreAnyExprIntoOneUnit(CGF, Init, E->getAllocatedType(), NewPtr);<br>
> }<br>
><br>
> /// Emit a call to an operator new or operator delete function, as implicitly<br>
> @@ -1269,9 +1265,6 @@ llvm::Value *CodeGenFunction::EmitCXXNew<br>
>                E->placement_arg_end(), /* CalleeDecl */ nullptr,<br>
>                /*ParamsToSkip*/ 1);<br>
><br>
> -  if (auto *DI = getDebugInfo())<br>
> -    DI->EmitLocation(Builder, E->getLocStart());<br>
> -<br>
>   // Emit the allocation call.  If the allocator is a global placement<br>
>   // operator, just "inline" it directly.<br>
>   RValue RV;<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -81,8 +81,7 @@ public:<br>
><br>
>   /// EmitStoreOfComplex - Store the specified real/imag parts into the<br>
>   /// specified value pointer.<br>
> -  void EmitStoreOfComplex(ComplexPairTy Val, LValue LV, bool isInit,<br>
> -                          SourceLocation DbgLoc);<br>
> +  void EmitStoreOfComplex(ComplexPairTy Val, LValue LV, bool isInit);<br>
><br>
>   /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType.<br>
>   ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType,<br>
> @@ -335,11 +334,7 @@ ComplexPairTy ComplexExprEmitter::EmitLo<br>
> /// EmitStoreOfComplex - Store the specified real/imag parts into the<br>
> /// specified value pointer.<br>
> void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,<br>
> -                                            bool isInit,<br>
> -                                            SourceLocation DbgLoc) {<br>
> -  if (auto *DI = CGF.getDebugInfo())<br>
> -    DI->EmitLocation(CGF.Builder, DbgLoc);<br>
> -<br>
> +                                            bool isInit) {<br>
>   if (lvalue.getType()->isAtomicType())<br>
>     return CGF.EmitAtomicStore(RValue::getComplex(Val), lvalue, isInit);<br>
><br>
> @@ -869,7 +864,7 @@ EmitCompoundAssignLValue(const CompoundA<br>
>   // Truncate the result and store it into the LHS lvalue.<br>
>   if (LHSTy->isAnyComplexType()) {<br>
>     ComplexPairTy ResVal = EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy);<br>
> -    EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false, E->getLocStart());<br>
> +    EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false);<br>
>     Val = RValue::getComplex(ResVal);<br>
>   } else {<br>
>     llvm::Value *ResVal =<br>
> @@ -914,7 +909,7 @@ LValue ComplexExprEmitter::EmitBinAssign<br>
>   LValue LHS = CGF.EmitLValue(E->getLHS());<br>
><br>
>   // Store the result value into the LHS lvalue.<br>
> -  EmitStoreOfComplex(Val, LHS, /*isInit*/ false, E->getLocStart());<br>
> +  EmitStoreOfComplex(Val, LHS, /*isInit*/ false);<br>
><br>
>   return LHS;<br>
> }<br>
> @@ -1042,19 +1037,18 @@ ComplexPairTy CodeGenFunction::EmitCompl<br>
> }<br>
><br>
> void CodeGenFunction::EmitComplexExprIntoLValue(const Expr *E, LValue dest,<br>
> -                                                bool isInit,<br>
> -                                                SourceLocation DbgLoc) {<br>
> +                                                bool isInit) {<br>
>   assert(E && getComplexType(E->getType()) &&<br>
>          "Invalid complex expression to emit");<br>
>   ComplexExprEmitter Emitter(*this);<br>
>   ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));<br>
> -  Emitter.EmitStoreOfComplex(Val, dest, isInit, DbgLoc);<br>
> +  Emitter.EmitStoreOfComplex(Val, dest, isInit);<br>
> }<br>
><br>
> /// EmitStoreOfComplex - Store a complex number into the specified l-value.<br>
> void CodeGenFunction::EmitStoreOfComplex(ComplexPairTy V, LValue dest,<br>
> -                                         bool isInit, SourceLocation DbgLoc) {<br>
> -  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit, DbgLoc);<br>
> +                                         bool isInit) {<br>
> +  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit);<br>
> }<br>
><br>
> /// EmitLoadOfComplex - Load a complex number from the specified address.<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -196,6 +196,7 @@ public:<br>
>   //===--------------------------------------------------------------------===//<br>
><br>
>   Value *Visit(Expr *E) {<br>
> +    ApplyDebugLocation DL(CGF, E->getLocStart());<br>
>     return StmtVisitor<ScalarExprEmitter, Value*>::Visit(E);<br>
>   }<br>
><br>
> @@ -3042,7 +3043,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(c<br>
>   // Emit an unconditional branch from this block to ContBlock.<br>
>   {<br>
>     // There is no need to emit line number for unconditional branch.<br>
> -    SuppressDebugLocation S(Builder);<br>
> +    ApplyDebugLocation DL(CGF);<br>
>     CGF.EmitBlock(ContBlock);<br>
>   }<br>
>   // Insert an entry into the phi node for the edge with the value of RHSCond.<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -565,7 +565,7 @@ void CodeGenFunction::EmitIfStmt(const I<br>
>   if (const Stmt *Else = S.getElse()) {<br>
>     {<br>
>       // There is no need to emit line number for unconditional branch.<br>
> -      SuppressDebugLocation S(Builder);<br>
> +      ApplyDebugLocation DL(*this);<br>
>       EmitBlock(ElseBlock);<br>
>     }<br>
>     {<br>
> @@ -574,7 +574,7 @@ void CodeGenFunction::EmitIfStmt(const I<br>
>     }<br>
>     {<br>
>       // There is no need to emit line number for unconditional branch.<br>
> -      SuppressDebugLocation S(Builder);<br>
> +      ApplyDebugLocation DL(*this);<br>
>       EmitBranch(ContBlock);<br>
>     }<br>
>   }<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -86,13 +86,13 @@ static void EmitOMPIfClause(CodeGenFunct<br>
>   // Emit the 'else' code if present.<br>
>   {<br>
>     // There is no need to emit line number for unconditional branch.<br>
> -    SuppressDebugLocation SDL(CGF.Builder);<br>
> +    ApplyDebugLocation DL(CGF);<br>
>     CGF.EmitBlock(ElseBlock);<br>
>   }<br>
>   CodeGen(/*ThenBlock*/ false);<br>
>   {<br>
>     // There is no need to emit line number for unconditional branch.<br>
> -    SuppressDebugLocation SDL(CGF.Builder);<br>
> +    ApplyDebugLocation DL(CGF);<br>
>     CGF.EmitBranch(ContBlock);<br>
>   }<br>
>   // Emit the continuation block for code after the if.<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -158,7 +158,7 @@ TypeEvaluationKind CodeGenFunction::getE<br>
>   }<br>
> }<br>
><br>
> -void CodeGenFunction::EmitReturnBlock() {<br>
> +llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {<br>
>   // For cleanliness, we try to avoid emitting the return block for<br>
>   // simple cases.<br>
>   llvm::BasicBlock *CurBB = Builder.GetInsertBlock();<br>
> @@ -173,7 +173,7 @@ void CodeGenFunction::EmitReturnBlock()<br>
>       delete ReturnBlock.getBlock();<br>
>     } else<br>
>       EmitBlock(ReturnBlock.getBlock());<br>
> -    return;<br>
> +    return llvm::DebugLoc();<br>
>   }<br>
><br>
>   // Otherwise, if the return block is the target of a single direct<br>
> @@ -184,15 +184,13 @@ void CodeGenFunction::EmitReturnBlock()<br>
>       dyn_cast<llvm::BranchInst>(*ReturnBlock.getBlock()->user_begin());<br>
>     if (BI && BI->isUnconditional() &&<br>
>         BI->getSuccessor(0) == ReturnBlock.getBlock()) {<br>
> -      // Reset insertion point, including debug location, and delete the<br>
> -      // branch.  This is really subtle and only works because the next change<br>
> -      // in location will hit the caching in CGDebugInfo::EmitLocation and not<br>
> -      // override this.<br>
> -      Builder.SetCurrentDebugLocation(BI->getDebugLoc());<br>
> +      // Record/return the DebugLoc of the simple 'return' expression to be used<br>
> +      // later by the actual 'ret' instruction.<br>
> +      llvm::DebugLoc Loc = BI->getDebugLoc();<br>
>       Builder.SetInsertPoint(BI->getParent());<br>
>       BI->eraseFromParent();<br>
>       delete ReturnBlock.getBlock();<br>
> -      return;<br>
> +      return Loc;<br>
>     }<br>
>   }<br>
><br>
> @@ -201,6 +199,7 @@ void CodeGenFunction::EmitReturnBlock()<br>
>   // region.end for now.<br>
><br>
>   EmitBlock(ReturnBlock.getBlock());<br>
> +  return llvm::DebugLoc();<br>
> }<br>
><br>
> static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB) {<br>
> @@ -254,16 +253,18 @@ void CodeGenFunction::FinishFunction(Sou<br>
>   }<br>
><br>
>   // Emit function epilog (to return).<br>
> -  EmitReturnBlock();<br>
> +  llvm::DebugLoc Loc = EmitReturnBlock();<br>
><br>
>   if (ShouldInstrumentFunction())<br>
>     EmitFunctionInstrumentation("__cyg_profile_func_exit");<br>
><br>
>   // Emit debug descriptor for function end.<br>
> -  if (CGDebugInfo *DI = getDebugInfo()) {<br>
> +  if (CGDebugInfo *DI = getDebugInfo())<br>
>     DI->EmitFunctionEnd(Builder);<br>
> -  }<br>
><br>
> +  // Reset the debug location to that of the simple 'return' expression, if any<br>
> +  // rather than that of the end of the function's scope '}'.<br>
> +  ApplyDebugLocation AL(*this, Loc);<br>
>   EmitFunctionEpilog(*CurFnInfo, EmitRetDbgLoc, EndLoc);<br>
>   EmitEndEHSpec(CurCodeDecl);<br>
><br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Jan 14 01:38:27 2015<br>
> @@ -93,19 +93,6 @@ enum TypeEvaluationKind {<br>
>   TEK_Aggregate<br>
> };<br>
><br>
> -class SuppressDebugLocation {<br>
> -  llvm::DebugLoc CurLoc;<br>
> -  llvm::IRBuilderBase &Builder;<br>
> -public:<br>
> -  SuppressDebugLocation(llvm::IRBuilderBase &Builder)<br>
> -      : CurLoc(Builder.getCurrentDebugLocation()), Builder(Builder) {<br>
> -    Builder.SetCurrentDebugLocation(llvm::DebugLoc());<br>
> -  }<br>
> -  ~SuppressDebugLocation() {<br>
> -    Builder.SetCurrentDebugLocation(CurLoc);<br>
> -  }<br>
> -};<br>
> -<br>
> /// CodeGenFunction - This class organizes the per-function state that is used<br>
> /// while generating LLVM code.<br>
> class CodeGenFunction : public CodeGenTypeCache {<br>
> @@ -1273,7 +1260,7 @@ public:<br>
><br>
>   /// EmitReturnBlock - Emit the unified return block, trying to avoid its<br>
>   /// emission when possible.<br>
> -  void EmitReturnBlock();<br>
> +  llvm::DebugLoc EmitReturnBlock();<br>
><br>
>   /// FinishFunction - Complete IR generation of the current function. It is<br>
>   /// legal to call this function even if there is no current insertion point.<br>
> @@ -1298,8 +1285,7 @@ public:<br>
>                         FunctionArgList &Args);<br>
><br>
>   void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init,<br>
> -                               ArrayRef<VarDecl *> ArrayIndexes,<br>
> -                               SourceLocation DbgLoc = SourceLocation());<br>
> +                               ArrayRef<VarDecl *> ArrayIndexes);<br>
><br>
>   /// InitializeVTablePointer - Initialize the vtable pointer of the given<br>
>   /// subobject.<br>
> @@ -1544,7 +1530,7 @@ public:<br>
>   /// EmitExprAsInit - Emits the code necessary to initialize a<br>
>   /// location in memory with the given initializer.<br>
>   void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue,<br>
> -                      bool capturedByInit, SourceLocation DbgLoc);<br>
> +                      bool capturedByInit);<br>
><br>
>   /// hasVolatileMember - returns true if aggregate type has a volatile<br>
>   /// member.<br>
> @@ -1831,8 +1817,7 @@ public:<br>
>   void EmitVarDecl(const VarDecl &D);<br>
><br>
>   void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue,<br>
> -                      bool capturedByInit,<br>
> -                      SourceLocation DbgLoc = SourceLocation());<br>
> +                      bool capturedByInit);<br>
>   void EmitScalarInit(llvm::Value *init, LValue lvalue);<br>
><br>
>   typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,<br>
> @@ -2162,8 +2147,7 @@ public:<br>
>   /// EmitStoreThroughLValue - Store the specified rvalue into the specified<br>
>   /// lvalue, where both are guaranteed to the have the same type, and that type<br>
>   /// is 'Ty'.<br>
> -  void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false,<br>
> -                              SourceLocation DbgLoc = SourceLocation());<br>
> +  void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit = false);<br>
>   void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);<br>
>   void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst);<br>
><br>
> @@ -2535,12 +2519,10 @@ public:<br>
><br>
>   /// EmitComplexExprIntoLValue - Emit the given expression of complex<br>
>   /// type and place its result into the specified l-value.<br>
> -  void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit,<br>
> -                                 SourceLocation DbgLoc = SourceLocation());<br>
> +  void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);<br>
><br>
>   /// EmitStoreOfComplex - Store a complex number into the specified l-value.<br>
> -  void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit,<br>
> -                          SourceLocation DbgLoc = SourceLocation());<br>
> +  void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);<br>
><br>
>   /// EmitLoadOfComplex - Load a complex number from the specified l-value.<br>
>   ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc);<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/PR20038.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR20038.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR20038.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/PR20038.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/PR20038.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -1,4 +1,4 @@<br>
> -// RUN: %clang_cc1 -triple %itanium_abi_triple -g -emit-llvm  %s -o - | FileCheck %s<br>
> +// RUN: %clang_cc1 -triple %itanium_abi_triple -g -mllvm -no-discriminators -emit-llvm  %s -o - | FileCheck %s<br>
><br>
> struct C {<br>
>   ~C();<br>
> @@ -8,9 +8,7 @@ extern bool b;<br>
> // CHECK: call {{.*}}, !dbg [[DTOR_CALL2_LOC:![0-9]*]]<br>
> // CHECK: [[FUN1:.*]] = {{.*}}; [ DW_TAG_subprogram ] {{.*}} [def] [fun1]<br>
> // CHECK: [[FUN2:.*]] = {{.*}}; [ DW_TAG_subprogram ] {{.*}} [def] [fun2]<br>
> -// CHECK: [[DTOR_CALL1_LOC]] = !{i32 [[@LINE+2]], i32 0, [[FUN1_BLOCK:.*]], null}<br>
> -// CHECK: [[FUN1_BLOCK]] = !{!"0xb{{[^,]*}}", {{[^,]*}}, [[FUN1]]}<br>
> +// CHECK: [[DTOR_CALL1_LOC]] = !{i32 [[@LINE+1]], i32 0, [[FUN1]], null}<br>
> void fun1() { b && (C(), 1); }<br>
> -// CHECK: [[DTOR_CALL2_LOC]] = !{i32 [[@LINE+2]], i32 0, [[FUN2_BLOCK1:.*]], null}<br>
> -// CHECK: [[FUN2_BLOCK1]] = !{!"0xb{{[^,]*}}", {{[^,]*}}, [[FUN2]]}<br>
> +// CHECK: [[DTOR_CALL2_LOC]] = !{i32 [[@LINE+1]], i32 0, [[FUN2]], null}<br>
> bool fun2() { return (C(), b) && 0; }<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -1,4 +1,7 @@<br>
> -// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -g -std=c++11 -S -emit-llvm %s -o - | FileCheck %s<br>
> +// RUN: %clang_cc1 -gline-tables-only -std=c++11 -fexceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s<br>
> +// RUN: %clang_cc1 -gline-tables-only -std=c++11 -fexceptions -fcxx-exceptions -S -emit-llvm %s -o - -triple i686-linux-gnu | FileCheck %s<br>
> +<br>
> +// XFAIL: win32<br>
><br>
> int &src();<br>
> int *sink();<br>
> @@ -123,6 +126,10 @@ struct bar {<br>
> // CHECK: invoke{{ }}<br>
> // CHECK: invoke{{ }}<br>
> // CHECK:   to label {{.*}}, !dbg [[DBG_GLBL_CTOR_B:!.*]]<br>
> +<br>
> +// terminate caller<br>
> +// CHECK-LABEL: define<br>
> +<br>
> // global dtor cleanup<br>
> // CHECK-LABEL: define<br>
> // CHECK: invoke{{ }}<br>
> @@ -133,6 +140,32 @@ bar b[1] = { //<br>
>     (fn(),   //<br>
>      bar())};<br>
><br>
> +// CHECK-LABEL: define<br>
> +__complex double f11() {<br>
> +  __complex double f;<br>
> +// CHECK: store {{.*}} !dbg [[DBG_F11:!.*]]<br>
> +#line 1200<br>
> +  return f;<br>
> +}<br>
> +<br>
> +// CHECK-LABEL: define<br>
> +void f12() {<br>
> +  int f12_1();<br>
> +  void f12_2(int = f12_1());<br>
> +// CHECK: call {{(signext )?}}i32 {{.*}} !dbg [[DBG_F12:!.*]]<br>
> +#line 1300<br>
> +  f12_2();<br>
> +}<br>
> +<br>
> +// CHECK-LABEL: define<br>
> +void f13() {<br>
> +// CHECK: call {{.*}} !dbg [[DBG_F13:!.*]]<br>
> +#define F13_IMPL 1, src()<br>
> +  1,<br>
> +#line 1400<br>
> +  F13_IMPL;<br>
> +}<br>
> +<br>
> // CHECK: [[DBG_F1]] = !{i32 100,<br>
> // CHECK: [[DBG_FOO_VALUE]] = !{i32 200,<br>
> // CHECK: [[DBG_FOO_REF]] = !{i32 202,<br>
> @@ -149,3 +182,6 @@ bar b[1] = { //<br>
> // CHECK: [[DBG_F10_STORE]] = !{i32 1100,<br>
> // CHECK: [[DBG_GLBL_CTOR_B]] = !{i32 1500,<br>
> // CHECK: [[DBG_GLBL_DTOR_B]] = !{i32 1500,<br>
> +// CHECK: [[DBG_F11]] = !{i32 1200,<br>
> +// CHECK: [[DBG_F12]] = !{i32 1300,<br>
> +// CHECK: [[DBG_F13]] = !{i32 1400,<br>
><br>
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp?rev=225956&r1=225955&r2=225956&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp?rev=225956&r1=225955&r2=225956&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp (original)<br>
> +++ cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp Wed Jan 14 01:38:27 2015<br>
> @@ -36,12 +36,12 @@ void func() {<br>
>   // CHECK: = !{!"0x100\00{{.*}}", [[FOR:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [i] [line [[@LINE+2]]]<br>
>   // CHECK: [[FOR]] = !{!"0xb\00[[@LINE+1]]\00{{.*}}", !{{.*}}} ; [ DW_TAG_lexical_block ]<br>
>   for (int i = 0; i != 10; ++i) {<br>
> -  // FIXME: Do not include scopes that have only other scopes (and no variables<br>
> -  // or using declarations) as direct children, they just waste<br>
> -  // space/relocations/etc.<br>
> -  // CHECK: = !{!"0x100\00{{.*}}", [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+3]]]<br>
> -  // CHECK: [[FOR_COMPOUND]] = !{!"0xb\00[[@LINE-5]]\00{{.*}}", !{{[0-9]+}}, [[FOR_BODY:![0-9]+]]} ; [ DW_TAG_lexical_block ]<br>
> -  // CHECK: [[FOR_BODY]] = !{!"0xb\00[[@LINE-6]]\00{{.*}}", !{{[0-9]+}}, [[FOR]]} ; [ DW_TAG_lexical_block ]<br>
> +    // FIXME: Do not include scopes that have only other scopes (and no variables<br>
> +    // or using declarations) as direct children, they just waste<br>
> +    // space/relocations/etc.<br>
> +    // CHECK: [[FOR_LOOP_INCLUDING_COND:!.*]] = !{!"0xb\00[[@LINE-4]]\00{{.*}}", !{{[0-9]+}}, [[FOR]]} ; [ DW_TAG_lexical_block ]<br>
> +    // CHECK: = !{!"0x100\00{{.*}}", [[FOR_COMPOUND:![0-9]*]], {{.*}} ; [ DW_TAG_auto_variable ] [b] [line [[@LINE+2]]]<br>
> +    // CHECK: [[FOR_COMPOUND]] = !{!"0xb\00[[@LINE-6]]\00{{.*}}", !{{[0-9]+}}, [[FOR_LOOP_INCLUDING_COND]]} ; [ DW_TAG_lexical_block ]<br>
>     bool b = i % 2;<br>
>   }<br>
><br>
><br>
><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>
<br>
</div></div></blockquote></div><br></div></div>