Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -421,13 +421,18 @@ return cast(V); } + const FileID foundIdFromLoc = SM.getFileID(Loc); SmallString<32> Checksum; - Optional CSKind = - computeChecksum(SM.getFileID(Loc), Checksum); + Optional CSKind; Optional> CSInfo; - if (CSKind) - CSInfo.emplace(*CSKind, Checksum); - return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc))); + const FileEntry *fileEntry = SM.getFileEntryForID(foundIdFromLoc); + if (!fileEntry || fileEntry->getName().empty() || + fileEntry->getName().equals(FileName)) { + CSKind = computeChecksum(foundIdFromLoc, Checksum); + if (CSKind) + CSInfo.emplace(*CSKind, Checksum); + } + return createFile(FileName, CSInfo, getSource(SM, foundIdFromLoc)); } llvm::DIFile * Index: test/Driver/cl-preprocess-md5.cpp =================================================================== --- test/Driver/cl-preprocess-md5.cpp +++ test/Driver/cl-preprocess-md5.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cl /c %s /Z7 /Fo%t.obj +// RUN: llvm-pdbutil dump -l %t.obj | grep -E " \(MD5: ([0-9A-F]+)\)" | sed -n -e 's/^.*MD5: //p' | sort | uniq | wc -l | FileCheck %s --check-prefix=GOOD-SIZE +// GOOD-SIZE-NOT: 1 + +// RUN: %clang_cl /c %s /Z7 /E >%t.cpp +// RUN: %clang_cl /c %t.cpp /Z7 /Fo%t.obj +// RUN: llvm-pdbutil dump -l %t.obj | not grep -E " \(MD5: ([0-9A-F]+)\)" +// RUN: llvm-pdbutil dump -l %t.obj | grep " (no checksum)" +// + +#include +int main() { + std::string A{"a"}; + return 0; +}