diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 4 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.h | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp | 6 |
3 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index efacc35d149..675b5eb07c5 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2224,8 +2224,12 @@ llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) { // option. FullSourceLoc Loc(D->getLocation(), CGM.getContext().getSourceManager()); if (Module *M = ClangModuleMap->inferModuleFromLocation(Loc)) { + // This is a (sub-)module. auto Info = ExternalASTSource::ASTSourceDescriptor(*M); return getOrCreateModuleRef(Info, /*SkeletonCU=*/false); + } else { + // This the precompiled header being built. + return getOrCreateModuleRef(PCHDescriptor, /*SkeletonCU=*/false); } } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index a68dd33fa5f..55d813834e8 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -16,6 +16,7 @@ #include "CGBuilder.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" @@ -57,6 +58,7 @@ class CGDebugInfo { llvm::DIBuilder DBuilder; llvm::DICompileUnit *TheCU = nullptr; ModuleMap *ClangModuleMap = nullptr; + ExternalASTSource::ASTSourceDescriptor PCHDescriptor; SourceLocation CurLoc; llvm::DIType *VTablePtrType = nullptr; llvm::DIType *ClassTy = nullptr; @@ -275,6 +277,8 @@ public: void finalize(); + /// Module debugging: Support for building PCMs. + /// @{ /// Set the main CU's DwoId field to \p Signature. void setDwoId(uint64_t Signature); @@ -283,6 +287,14 @@ public: /// the module of origin of each Decl. void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; } + /// When generating debug information for a clang module or + /// precompiled header, this module map will be used to determine + /// the module of origin of each Decl. + void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH) { + PCHDescriptor = PCH; + } + /// @} + /// Update the current source location. If \arg loc is invalid it is /// ignored. void setLocation(SourceLocation Loc); diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index 0e3aa61314e..406b433c95c 100644 --- a/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/clang/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -42,6 +42,7 @@ namespace { class PCHContainerGenerator : public ASTConsumer { DiagnosticsEngine &Diags; const std::string MainFileName; + const std::string OutputFileName; ASTContext *Ctx; ModuleMap &MMap; const HeaderSearchOptions &HeaderSearchOpts; @@ -137,7 +138,8 @@ public: const std::string &OutputFileName, raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) - : Diags(CI.getDiagnostics()), Ctx(nullptr), + : Diags(CI.getDiagnostics()), MainFileName(MainFileName), + OutputFileName(OutputFileName), Ctx(nullptr), MMap(CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()), HeaderSearchOpts(CI.getHeaderSearchOpts()), PreprocessorOpts(CI.getPreprocessorOpts()), @@ -163,6 +165,8 @@ public: Builder.reset(new CodeGen::CodeGenModule( *Ctx, HeaderSearchOpts, PreprocessorOpts, CodeGenOpts, *M, Diags)); Builder->getModuleDebugInfo()->setModuleMap(MMap); + Builder->getModuleDebugInfo()->setPCHDescriptor( + {MainFileName, "", OutputFileName, ~1ULL}); } bool HandleTopLevelDecl(DeclGroupRef D) override { |