r361296 - [DebugInfo] Don't emit checksums when compiling a preprocessed CPP

Alexandre Ganea via cfe-commits cfe-commits at lists.llvm.org
Tue May 21 12:40:29 PDT 2019


Author: aganea
Date: Tue May 21 12:40:28 2019
New Revision: 361296

URL: http://llvm.org/viewvc/llvm-project?rev=361296&view=rev
Log:
[DebugInfo] Don't emit checksums when compiling a preprocessed CPP

Fixes PR41215

Differential Revision: https://reviews.llvm.org/D60283

Added:
    cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp
    cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
Modified:
    cfe/trunk/include/clang/Basic/SourceLocation.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGen/debug-info-file-checksum.c

Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=361296&r1=361295&r2=361296&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue May 21 12:40:28 2019
@@ -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.

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=361296&r1=361295&r2=361296&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue May 21 12:40:28 2019
@@ -1430,6 +1430,7 @@ PresumedLoc SourceManager::getPresumedLo
   // 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::getPresumedLo
     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::getPresumedLo
     }
   }
 
-  return PresumedLoc(Filename.data(), LineNo, ColNo, IncludeLoc);
+  return PresumedLoc(Filename.data(), FID, LineNo, ColNo, IncludeLoc);
 }
 
 /// Returns whether the PresumedLoc for a given SourceLocation is

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=361296&r1=361295&r2=361296&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue May 21 12:40:28 2019
@@ -422,8 +422,12 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
   }
 
   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);

Added: cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp?rev=361296&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp (added)
+++ cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-line.cpp Tue May 21 12:40:28 2019
@@ -0,0 +1,9 @@
+int foo(int x) {
+  return x+1;
+}
+
+#line 100
+void test1() {}
+
+#line 200
+void test2() {}

Added: cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp?rev=361296&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp (added)
+++ cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum-pre.cpp Tue May 21 12:40:28 2019
@@ -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;
+}

Modified: cfe/trunk/test/CodeGen/debug-info-file-checksum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-file-checksum.c?rev=361296&r1=361295&r2=361296&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/debug-info-file-checksum.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-file-checksum.c Tue May 21 12:40:28 2019
@@ -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")




More information about the cfe-commits mailing list