Index: test/tools/llvm-cov/Inputs/showTabsHTML.proftext =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/showTabsHTML.proftext @@ -0,0 +1,8 @@ +main +# Func Hash: +0 +# Num Counters: +1 +# Counter Values: +1 + Index: test/tools/llvm-cov/showTabsHTML.cpp =================================================================== --- /dev/null +++ test/tools/llvm-cov/showTabsHTML.cpp @@ -0,0 +1,37 @@ +// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/showTabsHTML.proftext +// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK %s +// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -instr-profile %t.profdata -filename-equivalence -name=main %s | FileCheck -check-prefix=CHECK %s + +int main(int argc, char ** argv) { + // CHECK:
1
+ // CHECK:
[[@LINE+2]]
+ // CHECK:
+	(void) "This tab starts at column 0";            // CHECK:   (void) "This tab starts at column 0";
+                                                     // CHECK: 
+ // CHECK:
1
+ // CHECK:
[[@LINE+2]]
+ // CHECK:
+  (void) "	This tab starts at column 10";           // CHECK: (void) "  This tab starts at column 10";
+                                                     // CHECK: 
1
+ // CHECK:
[[@LINE+2]]
+ // CHECK:
+  (void) "This 	 tab starts at column 15";           // CHECK: (void) "This   tab starts at column 15";
+
+  return 0;
+}
+
+// RUN: llvm-cov show %S/Inputs/showTabsHTML.covmapping -format html -tab-size=3 -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK-TABSIZE %s
+
+// CHECK-TABSIZE: 
1
+// CHECK-TABSIZE:
[[@LINE-17]]
+// CHECK-TABSIZE:
+// CHECK-TABSIZE:    (void) "This tab starts at column 0";
+// CHECK-TABSIZE: 
+// CHECK-TABSIZE:
1
+// CHECK-TABSIZE:
[[@LINE-17]]
+// CHECK-TABSIZE:
+// CHECK-TABSIZE: (void) "  This tab starts at column 10";
+// CHECK-TABSIZE: 
1
+// CHECK-TABSIZE:
[[@LINE-17]]
+// CHECK-TABSIZE:
+// CHECK-TABSIZE: (void) "This     tab starts at column 15";
\ No newline at end of file
Index: tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- tools/llvm-cov/CodeCoverage.cpp
+++ tools/llvm-cov/CodeCoverage.cpp
@@ -584,6 +584,10 @@
   cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
                                  cl::aliasopt(ShowOutputDirectory));
 
+  cl::opt TabSize(
+      "tab-size", cl::Hidden, cl::init(2),
+      cl::desc("Set tab size for the HTML coverage report (default = 2)"));
+
   auto Err = commandLineParser(argc, argv);
   if (Err)
     return Err;
@@ -596,6 +600,7 @@
   ViewOpts.ShowExpandedRegions = ShowExpansions;
   ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
   ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
+  ViewOpts.TabSize = TabSize;
 
   if (ViewOpts.hasOutputDirectory()) {
     if (auto E = sys::fs::create_directories(ViewOpts.ShowOutputDirectory)) {
Index: tools/llvm-cov/CoverageViewOptions.h
===================================================================
--- tools/llvm-cov/CoverageViewOptions.h
+++ tools/llvm-cov/CoverageViewOptions.h
@@ -34,6 +34,7 @@
   OutputFormat Format;
   std::string ShowOutputDirectory;
   std::vector DemanglerOpts;
+  static uint32_t TabSize;
 
   /// \brief Change the output's stream color if the colors are enabled.
   ColoredRawOstream colored_ostream(raw_ostream &OS,
Index: tools/llvm-cov/SourceCoverageViewHTML.cpp
===================================================================
--- tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -18,13 +18,16 @@
 #include "llvm/Support/Path.h"
 
 using namespace llvm;
+uint32_t CoverageViewOptions::TabSize;
 
 namespace {
 
 // Return a string with the special characters in \p Str escaped.
 std::string escape(StringRef Str) {
   std::string Result;
+  unsigned ColNum = 0;        // Record the column number.
   for (char C : Str) {
+    ++ColNum;
     if (C == '&')
       Result += "&";
     else if (C == '<')
@@ -33,7 +36,17 @@
       Result += ">";
     else if (C == '\"')
       Result += """;
-    else
+    // Replace '\t' with 2-space indentation.
+    else if (C == '\n' || C == '\r') {
+      Result += C;
+      ColNum = 0;
+    } else if (C == '\t') {
+      unsigned NumSpaces = CoverageViewOptions::TabSize -
+                           (--ColNum % CoverageViewOptions::TabSize);
+      for (unsigned i = 0; i < NumSpaces; ++i)
+        Result += " ";
+      ColNum += NumSpaces;
+    } else
       Result += C;
   }
   return Result;