]> granicus.if.org Git - clang/commitdiff
[DebugInfo] Don't bother with MD5 checksums of preprocessed files.
authorPaul Robinson <paul.robinson@sony.com>
Fri, 25 May 2018 20:59:29 +0000 (20:59 +0000)
committerPaul Robinson <paul.robinson@sony.com>
Fri, 25 May 2018 20:59:29 +0000 (20:59 +0000)
The checksum will not reflect the real source, so there's no clear
reason to include them in the debug info.  Also this was causing a
crash on the DWARF side.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333311 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
test/CodeGen/md5-checksum-crash.c [new file with mode: 0644]

index 9e99a646b0bff2ca89580f77b923e8dcef20c23b..8cf37f48a27ef701040024b94c662801f78106d4 100644 (file)
@@ -67,6 +67,8 @@ CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
       DBuilder(CGM.getModule()) {
   for (const auto &KV : CGM.getCodeGenOpts().DebugPrefixMap)
     DebugPrefixMap[KV.first] = KV.second;
+  EmitFileChecksums = CGM.getCodeGenOpts().EmitCodeView ||
+                      CGM.getCodeGenOpts().DwarfVersion >= 5;
   CreateCompileUnit();
 }
 
@@ -365,15 +367,21 @@ Optional<llvm::DIFile::ChecksumKind>
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView &&
-      CGM.getCodeGenOpts().DwarfVersion < 5)
+  if (!EmitFileChecksums)
     return None;
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   bool Invalid;
-  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
-  if (Invalid)
+  const SrcMgr::SLocEntry &Entry = SM.getSLocEntry(FID, &Invalid);
+  if (Invalid || !Entry.isFile())
     return None;
+  if (Entry.getFile().hasLineDirectives()) {
+    // This must be a preprocessed file; its content won't match the original
+    // source; therefore checksumming the text we have is pointless or wrong.
+    EmitFileChecksums = false;
+    return None;
+  }
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID);
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;
index a692babef5369e436466610c5b0abc57ccdeb301..ec7b046c8f30aa47cb13bbf0fc50ea0c2ad6db95 100644 (file)
@@ -57,6 +57,7 @@ class CGDebugInfo {
   CodeGenModule &CGM;
   const codegenoptions::DebugInfoKind DebugKind;
   bool DebugTypeExtRefs;
+  mutable bool EmitFileChecksums;
   llvm::DIBuilder DBuilder;
   llvm::DICompileUnit *TheCU = nullptr;
   ModuleMap *ClangModuleMap = nullptr;
diff --git a/test/CodeGen/md5-checksum-crash.c b/test/CodeGen/md5-checksum-crash.c
new file mode 100644 (file)
index 0000000..7a4d487
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -dwarf-version=5 %s -emit-llvm -o- | FileCheck %s
+// RUN: %clang_cc1 -triple %ms_abi_triple -gcodeview -debug-info-kind=limited %s -emit-llvm -o- | FileCheck %s
+
+// This had been crashing, no MD5 checksum for string.h.
+// Now if there are #line directives, don't bother with checksums
+// as a preprocessed file won't properly reflect the original source.
+#define __NTH fct
+void fn1() {}
+# 7 "/usr/include/string.h"
+void __NTH() {}
+// Verify no checksum attributes on these files.
+// CHECK-DAG: DIFile(filename: "{{.*}}.c", directory: "{{[^"]*}}")
+// CHECK-DAG: DIFile(filename: "{{.*}}string.h", directory: "{{[^"]*}}")