calixte created this revision.
calixte added reviewers: marco-c, davidxl.
Herald added a subscriber: cfe-commits.

Some lines have a hit counter where they should not have one.
Cleanup stuff is located to the last line of the body which is most of the time 
a '}'.
And Exception stuff is added at the beginning of a function and at the end 
(represented by '{' and '}').
So in such cases, the DebugLoc used in GCOVProfiling.cpp must be marked as not 
covered.
This patch is a followup of https://reviews.llvm.org/D49915.


Repository:
  rC Clang

https://reviews.llvm.org/D49916

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h

Index: lib/CodeGen/CodeGenFunction.h
===================================================================
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -785,7 +785,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(), false /* Covered */);
         ForceCleanup();
       }
     }
Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1174,7 +1174,7 @@
   }
   // Emit a location at the end of the prologue.
   if (CGDebugInfo *DI = getDebugInfo())
-    DI->EmitLocation(Builder, StartLoc);
+    DI->EmitLocation(Builder, StartLoc, false /* Covered */);
 
   // TODO: Do we need to handle this in two places like we do with
   // target-features/target-cpu?
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -361,7 +361,8 @@
   /// 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 Covered   True if the Loc must have coverage information 
+  void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, bool Covered = true);
 
   /// Emit a call to llvm.dbg.function.start to indicate
   /// start of a new function.
@@ -641,16 +642,16 @@
 /// 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 Covered = true);
   ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
                      SourceLocation TemporaryLocation);
 
   llvm::DebugLoc OriginalLocation;
   CodeGenFunction *CGF;
 
 public:
   /// Set the location to the (valid) TemporaryLocation.
-  ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
+  ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation, bool Covered = true);
   ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
   ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
   ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -76,9 +76,10 @@
 }
 
 ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
-                                       SourceLocation TemporaryLocation)
+                                       SourceLocation TemporaryLocation,
+                                       bool Covered)
     : CGF(&CGF) {
-  init(TemporaryLocation);
+  init(TemporaryLocation, false /* DefaultToEmpty */, Covered);
 }
 
 ApplyDebugLocation::ApplyDebugLocation(CodeGenFunction &CGF,
@@ -89,7 +90,8 @@
 }
 
 void ApplyDebugLocation::init(SourceLocation TemporaryLocation,
-                              bool DefaultToEmpty) {
+                              bool DefaultToEmpty,
+                              bool Covered) {
   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, Covered);
     return;
   }
 
@@ -3444,16 +3446,16 @@
   setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
 }
 
-void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {
+void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, bool Covered) {
   // Update our current location
   setLocation(Loc);
 
   if (CurLoc.isInvalid() || CurLoc.isMacroID())
     return;
 
   llvm::MDNode *Scope = LexicalBlockStack.back();
   Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
-      getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt));
+      getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt, Covered));
 }
 
 void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
@@ -3500,7 +3502,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, false /* Covered */);
 
   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
     return;
@@ -3516,7 +3518,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, false /* Covered */);
     LexicalBlockStack.pop_back();
   }
   FnBeginRegionCount.pop_back();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D49916: [CodeGen] Ad... calixte via Phabricator via cfe-commits

Reply via email to