diff --git a/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.c.html b/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.c.html
index 0a706b631c98..225ebabdbde3 100644
--- a/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.c.html
+++ b/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.c.html
@@ -1,5 +1,6 @@
+
or.c
diff --git a/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.h.html b/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.h.html
index 6ca5a18f29d9..7cbda8a66c76 100644
--- a/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.h.html
+++ b/llvm/test/tools/opt-viewer/Outputs/basic/basic_or.h.html
@@ -1,5 +1,6 @@
+or.h
diff --git a/llvm/test/tools/opt-viewer/Outputs/suppress/s.swift.html b/llvm/test/tools/opt-viewer/Outputs/suppress/s.swift.html
index eae4c4f56102..813db9f98205 100644
--- a/llvm/test/tools/opt-viewer/Outputs/suppress/s.swift.html
+++ b/llvm/test/tools/opt-viewer/Outputs/suppress/s.swift.html
@@ -1,5 +1,6 @@
+s.swift
diff --git a/llvm/test/tools/opt-viewer/Outputs/unicode-function-name/s.swift.html b/llvm/test/tools/opt-viewer/Outputs/unicode-function-name/s.swift.html
index 470c7f8061a0..67514d556c38 100644
--- a/llvm/test/tools/opt-viewer/Outputs/unicode-function-name/s.swift.html
+++ b/llvm/test/tools/opt-viewer/Outputs/unicode-function-name/s.swift.html
@@ -1,5 +1,6 @@
+s.swift
diff --git a/llvm/tools/opt-viewer/opt-viewer.py b/llvm/tools/opt-viewer/opt-viewer.py
index a3eaba1495cd..4887043e0f96 100755
--- a/llvm/tools/opt-viewer/opt-viewer.py
+++ b/llvm/tools/opt-viewer/opt-viewer.py
@@ -44,6 +44,7 @@ def suppress(remark):
class SourceFileRenderer:
def __init__(self, source_dir, output_dir, filename, no_highlight):
+ self.filename = filename
existing_filename = None
if os.path.exists(filename):
existing_filename = filename
@@ -131,6 +132,7 @@ class SourceFileRenderer:
print('''
+{}
@@ -147,7 +149,7 @@ class SourceFileRenderer:
Inline Context
- | ''', file=self.stream)
+'''.format(os.path.basename(self.filename)), file=self.stream)
self.render_source_lines(self.source_stream, line_remarks)
print('''