Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -404,17 +404,22 @@ } llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) { - if (!Loc.isValid()) - // If Location is not valid then use main input file. - return TheCU->getFile(); SourceManager &SM = CGM.getContext().getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(Loc); - StringRef FileName = PLoc.getFilename(); - if (PLoc.isInvalid() || FileName.empty()) - // If the location is not valid then use main input file. - return TheCU->getFile(); + SmallString<32> Checksum; + + if (Loc.isInvalid() && FileName.empty()){ + Optional CSKind = + computeChecksum(PLoc.getFileID(), Checksum); + Optional> CSInfo; + + if (CSKind) + CSInfo.emplace(*CSKind, Checksum); + + return createFile(TheCU->getFile()->getFilename(), CSInfo, getSource(SM, SM.getFileID(Loc))); + } // Cache the results. auto It = DIFileCache.find(FileName.data()); @@ -424,8 +429,6 @@ return cast(V); } - 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. Index: clang/test/CodeGenCXX/difile_entry.cpp =================================================================== --- clang/test/CodeGenCXX/difile_entry.cpp +++ clang/test/CodeGenCXX/difile_entry.cpp @@ -0,0 +1,12 @@ +// RUN: rm -rf %t/test_dir +// RUN: mkdir -p %t/test_dir +// RUN: cd %t/test_dir +// RUN: cp %s . +// RUN: %clang_cc1 -main-file-name difile_entry.cpp -debug-info-kind=limited ../test_dir/difile_entry.cpp -std=c++11 -emit-llvm -o - | FileCheck ../test_dir/difile_entry.cpp +int x(); +static int i = x(); + +// CHECK: [[FILE: *]] = !DIFile(filename: "{{.*}}difile_entry.cpp", +// CHECK: {{.*}} = distinct !DISubprogram(name: "__cxx_global_var_init", scope: {{.*}}, file: [[FILE]] +// CHECK: {{.*}} = distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_difile_entry.cpp", scope: {{.*}}, file: [[FILE]] +