Author: adrian Date: Tue Dec 11 08:58:43 2018 New Revision: 348865 URL: http://llvm.org/viewvc/llvm-project?rev=348865&view=rev Log: Reuse code from CGDebugInfo::getOrCreateFile() when creating the file for the DICompileUnit.
This addresses post-commit feedback for D55085. Without this patch, a main source file with an absolute paths may appear in different DIFiles, once with the absolute path and once with the common prefix between the absolute path and the current working directory. Differential Revision: https://reviews.llvm.org/D55519 Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/test/CodeGen/debug-info-compilation-dir.c cfe/trunk/test/PCH/debug-info-pch-path.c Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=348865&r1=348864&r2=348865&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Dec 11 08:58:43 2018 @@ -429,7 +429,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo; if (CSKind) CSInfo.emplace(*CSKind, Checksum); + return createFile(FileName, CSInfo, getSource(SM, SM.getFileID(Loc))); +} +llvm::DIFile * +CGDebugInfo::createFile(StringRef FileName, + Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo, + Optional<StringRef> Source) { StringRef Dir; StringRef File; std::string RemappedFile = remapDIPath(FileName); @@ -460,16 +466,13 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi Dir = CurDir; File = RemappedFile; } - llvm::DIFile *F = - DBuilder.createFile(File, Dir, CSInfo, - getSource(SM, SM.getFileID(Loc))); - + llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source); DIFileCache[FileName.data()].reset(F); return F; } llvm::DIFile *CGDebugInfo::getOrCreateMainFile() { - return DBuilder.createFile( + return createFile( remapDIPath(TheCU->getFilename()), remapDIPath(TheCU->getDirectory()), TheCU->getFile()->getChecksum(), CGM.getCodeGenOpts().EmbedSource ? TheCU->getSource() : None); @@ -607,9 +610,7 @@ void CGDebugInfo::CreateCompileUnit() { auto &CGOpts = CGM.getCodeGenOpts(); TheCU = DBuilder.createCompileUnit( LangTag, - DBuilder.createFile(remapDIPath(MainFileName), - remapDIPath(getCurrentDirname()), CSInfo, - getSource(SM, SM.getMainFileID())), + createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID())), CGOpts.EmitVersionIdentMetadata ? Producer : "", LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO, CGOpts.DwarfDebugFlags, RuntimeVers, Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=348865&r1=348864&r2=348865&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Dec 11 08:58:43 2018 @@ -538,9 +538,16 @@ private: /// Get the source of the given file ID. Optional<StringRef> getSource(const SourceManager &SM, FileID FID); - /// Get the file debug info descriptor for the input location. + /// Convenience function to get the file debug info descriptor for the input + /// location. llvm::DIFile *getOrCreateFile(SourceLocation Loc); + /// Create a file debug info descriptor for a source file. + llvm::DIFile * + createFile(StringRef FileName, + Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo, + Optional<StringRef> Source); + /// Get the file info for main compile unit. llvm::DIFile *getOrCreateMainFile(); Modified: cfe/trunk/test/CodeGen/debug-info-compilation-dir.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-compilation-dir.c?rev=348865&r1=348864&r2=348865&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/debug-info-compilation-dir.c (original) +++ cfe/trunk/test/CodeGen/debug-info-compilation-dir.c Tue Dec 11 08:58:43 2018 @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-NONSENSE %s +// RUN: mkdir -p %t.dir && cd %t.dir +// RUN: cp %s rel.c +// RUN: %clang_cc1 -fdebug-compilation-dir /nonsense -emit-llvm -debug-info-kind=limited rel.c -o - | FileCheck -check-prefix=CHECK-NONSENSE %s // CHECK-NONSENSE: nonsense // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck -check-prefix=CHECK-DIR %s Modified: cfe/trunk/test/PCH/debug-info-pch-path.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/debug-info-pch-path.c?rev=348865&r1=348864&r2=348865&view=diff ============================================================================== --- cfe/trunk/test/PCH/debug-info-pch-path.c (original) +++ cfe/trunk/test/PCH/debug-info-pch-path.c Tue Dec 11 08:58:43 2018 @@ -24,7 +24,7 @@ // CHECK-REL-NODIR: !DICompileUnit( // CHECK-REL-NODIR-SAME: file: ![[PCH:[0-9]+]] // CHECK-REL-NODIR-SAME: splitDebugFilename: "prefix.pch" -// CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]" +// CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]] // --------------------------------------------------------------------- // Relative PCH in a subdirectory. @@ -71,4 +71,4 @@ // CHECK-ABS: !DICompileUnit( // CHECK-ABS-SAME: file: ![[PCH:[0-9]+]] // CHECK-ABS-SAME: splitDebugFilename: "prefix.pch" -// CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]" +// CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits