summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>2019-05-21 19:40:28 +0000
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>2019-05-21 19:40:28 +0000
commit047e65db77571bb586429a8094b3dfa43cecd449 (patch)
treef82cd9abcbd0023fe8625bd40a16ed05378ef404
parentb07176666b8ec276902d207f8ee0f832323a2128 (diff)
downloadbcm5719-llvm-047e65db77571bb586429a8094b3dfa43cecd449.tar.gz
bcm5719-llvm-047e65db77571bb586429a8094b3dfa43cecd449.zip
[DebugInfo] Don't emit checksums when compiling a preprocessed CPP
Fixes PR41215 Differential Revision: https://reviews.llvm.org/D60283 llvm-svn: 361296
-rw-r--r--clang/include/clang/Basic/SourceLocation.h11
-rw-r--r--clang/lib/Basic/SourceManager.cpp9
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp6
-rw-r--r--clang/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp9
-rw-r--r--clang/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp10
-rw-r--r--clang/test/CodeGen/debug-info-file-checksum.c12
6 files changed, 52 insertions, 5 deletions
diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h
index ceebdf48225..d6e2f6e6de9 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -282,13 +282,15 @@ public:
/// You can get a PresumedLoc from a SourceLocation with SourceManager.
class PresumedLoc {
const char *Filename = nullptr;
+ FileID ID;
unsigned Line, Col;
SourceLocation IncludeLoc;
public:
PresumedLoc() = default;
- PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
- : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {}
+ PresumedLoc(const char *FN, FileID FID, unsigned Ln, unsigned Co,
+ SourceLocation IL)
+ : Filename(FN), ID(FID), Line(Ln), Col(Co), IncludeLoc(IL) {}
/// Return true if this object is invalid or uninitialized.
///
@@ -305,6 +307,11 @@ public:
return Filename;
}
+ FileID getFileID() const {
+ assert(isValid());
+ return ID;
+ }
+
/// Return the presumed line number of this location.
///
/// This can be affected by \#line etc.
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 712cbb0d0ea..e62cef7ec55 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1430,6 +1430,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,
// To get the source name, first consult the FileEntry (if one exists)
// before the MemBuffer as this will avoid unnecessarily paging in the
// MemBuffer.
+ FileID FID = LocInfo.first;
StringRef Filename;
if (C->OrigEntry)
Filename = C->OrigEntry->getName();
@@ -1453,8 +1454,12 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,
if (const LineEntry *Entry =
LineTable->FindNearestLineEntry(LocInfo.first, LocInfo.second)) {
// If the LineEntry indicates a filename, use it.
- if (Entry->FilenameID != -1)
+ if (Entry->FilenameID != -1) {
Filename = LineTable->getFilename(Entry->FilenameID);
+ // The contents of files referenced by #line are not in the
+ // SourceManager
+ FID = FileID::get(0);
+ }
// Use the line number specified by the LineEntry. This line number may
// be multiple lines down from the line entry. Add the difference in
@@ -1473,7 +1478,7 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc,
}
}
- return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc);
+ return PresumedLoc(Filename.data(), FID, LineNo, ColNo, IncludeLoc);
}
/// Returns whether the PresumedLoc for a given SourceLocation is
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4c43c00cd5e..f436cab16c4 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -422,8 +422,12 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
}
SmallString<32> Checksum;
+
+ // Compute the checksum if possible. If the location is affected by a #line
+ // directive that refers to a file, PLoc will have an invalid FileID, and we
+ // will correctly get no checksum.
Optional<llvm::DIFile::ChecksumKind> CSKind =
- computeChecksum(SM.getFileID(Loc), Checksum);
+ computeChecksum(PLoc.getFileID(), Checksum);
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
if (CSKind)
CSInfo.emplace(*CSKind, Checksum);
diff --git a/clang/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp b/clang/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp
new file mode 100644
index 00000000000..e5fe98263a1
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp
@@ -0,0 +1,9 @@
+int foo(int x) {
+ return x+1;
+}
+
+#line 100
+void test1() {}
+
+#line 200
+void test2() {}
diff --git a/clang/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp b/clang/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
new file mode 100644
index 00000000000..11029e6b7a5
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
@@ -0,0 +1,10 @@
+#line 1 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+#line 1 "f:\\svn\\clang\\test\\codegen\\inputs\\code-coverage-filter1.h"
+void test1() {}
+#line 2 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+#line 1 "f:\\svn\\clang\\test\\codegen\\inputs\\code-coverage-filter2.h"
+void test2() {}
+#line 3 "F:\\svn\\clang\\test\\CodeGen\\Inputs\\debug-info-file-checksum.c"
+int foo(int x) {
+ return x+1;
+}
diff --git a/clang/test/CodeGen/debug-info-file-checksum.c b/clang/test/CodeGen/debug-info-file-checksum.c
index d644aac0614..273a10b0678 100644
--- a/clang/test/CodeGen/debug-info-file-checksum.c
+++ b/clang/test/CodeGen/debug-info-file-checksum.c
@@ -4,3 +4,15 @@
// Check that "checksum" is created correctly for the compiled file.
// CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
+
+// Ensure #line directives (in already pre-processed files) do not emit checksums
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-pre.cpp -o - | FileCheck %s --check-prefix NOCHECKSUM
+
+// NOCHECKSUM: !DIFile(filename: "{{.*}}code-coverage-filter1.h", directory: "{{[^"]*}}")
+// NOCHECKSUM: !DIFile(filename: "{{.*}}code-coverage-filter2.h", directory: "{{[^"]*}}")
+// NOCHECKSUM: !DIFile(filename: "{{.*}}debug-info-file-checksum.c", directory: "{{[^"]*}}")
+
+// Ensure #line directives without name do emit checksums
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum-line.cpp -o - | FileCheck %s --check-prefix CHECKSUM
+
+// CHECKSUM: !DIFile(filename: "{{.*}}debug-info-file-checksum-line.cpp", directory:{{.*}}, checksumkind: CSK_MD5, checksum: "7b568574d0e3c56c28e5e0234d1f4a06")
OpenPOWER on IntegriCloud