Index: lib/CodeGen/CGDebugInfo.h =================================================================== --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -377,7 +377,9 @@ /// Emit metadata to indicate a change in line/column information in /// the source file. If the location is invalid, the previous /// location will be reused. - void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc); + /// \param ImplicitCode True if the Loc must have coverage information + void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, + bool ImplicitCode = false); /// Emit a call to llvm.dbg.function.start to indicate /// start of a new function. @@ -657,16 +659,19 @@ /// location or preferred location of the specified Expr. class ApplyDebugLocation { private: - void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false); + void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false, + bool ImplicitCode = false); ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty, - SourceLocation TemporaryLocation); + SourceLocation TemporaryLocation, + bool ImplicitCode = false); llvm::DebugLoc OriginalLocation; CodeGenFunction *CGF; public: /// Set the location to the (valid) TemporaryLocation. - ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation); + ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation, + bool ImplicitCode = false); ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E); ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc); ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) { @@ -687,7 +692,8 @@ /// SourceLocation to CGDebugInfo::setLocation() will result in the /// last valid location being reused. static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) { - return ApplyDebugLocation(CGF, false, SourceLocation()); + return ApplyDebugLocation(CGF, false, SourceLocation(), + true /* ImplicitCode */); } /// Apply TemporaryLocation if it is valid. Otherwise switch /// to an artificial debug location that has a valid scope, but no @@ -695,7 +701,8 @@ static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation) { - return ApplyDebugLocation(CGF, false, TemporaryLocation); + return ApplyDebugLocation(CGF, false, TemporaryLocation, + true /* ImplicitCode */); } /// Set the IRBuilder to not attach debug locations. Note that Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -76,20 +76,22 @@ } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, - SourceLocation TemporaryLocation) + SourceLocation TemporaryLocation, + bool ImplicitCode) : CGF(&CGF) { - init(TemporaryLocation); + init(TemporaryLocation, false /* DefaultToEmpty */, ImplicitCode); } ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty, - SourceLocation TemporaryLocation) + SourceLocation TemporaryLocation, + bool ImplicitCode) : CGF(&CGF) { - init(TemporaryLocation, DefaultToEmpty); + init(TemporaryLocation, DefaultToEmpty, ImplicitCode); } void ApplyDebugLocation::init(SourceLocation TemporaryLocation, - bool DefaultToEmpty) { + bool DefaultToEmpty, bool ImplicitCode) { auto *DI = CGF->getDebugInfo(); if (!DI) { CGF = nullptr; @@ -102,7 +104,7 @@ return; if (TemporaryLocation.isValid()) { - DI->EmitLocation(CGF->Builder, TemporaryLocation); + DI->EmitLocation(CGF->Builder, TemporaryLocation, ImplicitCode); return; } @@ -3481,7 +3483,8 @@ setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt()); } -void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) { +void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, + bool ImplicitCode) { // Update our current location setLocation(Loc); @@ -3489,8 +3492,9 @@ return; llvm::MDNode *Scope = LexicalBlockStack.back(); - Builder.SetCurrentDebugLocation(llvm::DebugLoc::get( - getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt)); + Builder.SetCurrentDebugLocation( + llvm::DebugLoc::get(getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, + CurInlinedAt, ImplicitCode)); } void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) { @@ -3537,7 +3541,7 @@ assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); // Provide an entry in the line table for the end of the block. - EmitLocation(Builder, Loc); + EmitLocation(Builder, Loc, true /* ImplicitCode */); if (DebugKind <= codegenoptions::DebugLineTablesOnly) return; @@ -3553,7 +3557,7 @@ // Pop all regions for this function. while (LexicalBlockStack.size() != RCount) { // Provide an entry in the line table for the end of the block. - EmitLocation(Builder, CurLoc); + EmitLocation(Builder, CurLoc, true /* ImplicitCode */); LexicalBlockStack.pop_back(); } FnBeginRegionCount.pop_back(); Index: lib/CodeGen/CodeGenFunction.h =================================================================== --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -786,7 +786,7 @@ // If we should perform a cleanup, force them now. Note that // this ends the cleanup scope before rescoping any labels. if (PerformCleanup) { - ApplyDebugLocation DL(CGF, Range.getEnd()); + ApplyDebugLocation DL(CGF, Range.getEnd(), true /* ImplicitCode */); ForceCleanup(); } } Index: lib/CodeGen/CodeGenFunction.cpp =================================================================== --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -1179,7 +1179,7 @@ } // Emit a location at the end of the prologue. if (CGDebugInfo *DI = getDebugInfo()) - DI->EmitLocation(Builder, StartLoc); + DI->EmitLocation(Builder, StartLoc, true /* ImplicitCode */); // TODO: Do we need to handle this in two places like we do with // target-features/target-cpu?