diff options
Diffstat (limited to 'include/clang/Serialization')
| -rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 41 | ||||
| -rw-r--r-- | include/clang/Serialization/ASTDeserializationListener.h | 4 | ||||
| -rw-r--r-- | include/clang/Serialization/ASTReader.h | 133 | ||||
| -rw-r--r-- | include/clang/Serialization/ASTWriter.h | 67 | ||||
| -rw-r--r-- | include/clang/Serialization/ContinuousRangeMap.h | 12 | ||||
| -rw-r--r-- | include/clang/Serialization/GlobalModuleIndex.h | 6 | ||||
| -rw-r--r-- | include/clang/Serialization/Module.h | 18 | ||||
| -rw-r--r-- | include/clang/Serialization/ModuleManager.h | 23 | ||||
| -rw-r--r-- | include/clang/Serialization/SerializationDiagnostic.h | 4 | 
9 files changed, 234 insertions, 74 deletions
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 7ae1977d3e71..3874f3a64c1b 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -14,8 +14,8 @@  // respective lists.  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_FRONTEND_PCHBITCODES_H -#define LLVM_CLANG_FRONTEND_PCHBITCODES_H +#ifndef LLVM_CLANG_SERIALIZATION_ASTBITCODES_H +#define LLVM_CLANG_SERIALIZATION_ASTBITCODES_H  #include "clang/AST/Type.h"  #include "llvm/ADT/DenseMap.h" @@ -35,7 +35,7 @@ namespace clang {      /// Version 4 of AST files also requires that the version control branch and      /// revision match exactly, since there is no backward compatibility of      /// AST files at this time. -    const unsigned VERSION_MAJOR = 5; +    const unsigned VERSION_MAJOR = 6;      /// \brief AST file minor version number supported by this version of      /// Clang. @@ -288,7 +288,13 @@ namespace clang {        /// \brief Record code for the module map file that was used to build this        /// AST file. -      MODULE_MAP_FILE = 14 +      MODULE_MAP_FILE = 14, + +      /// \brief Record code for the signature that identifiers this AST file. +      SIGNATURE = 15, + +      /// \brief Record code for the module build directory. +      MODULE_DIRECTORY = 16,      };      /// \brief Record types that occur within the input-files block @@ -545,7 +551,10 @@ namespace clang {        LATE_PARSED_TEMPLATE = 50,        /// \brief Record code for \#pragma optimize options. -      OPTIMIZE_PRAGMA_OPTIONS = 51 +      OPTIMIZE_PRAGMA_OPTIONS = 51, + +      /// \brief Record code for potentially unused local typedef names. +      UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES = 52,      };      /// \brief Record types used within a source manager block. @@ -635,7 +644,13 @@ namespace clang {        /// \brief Specifies a conflict with another module.        SUBMODULE_CONFLICT = 12,        /// \brief Specifies a header that is private to this submodule. -      SUBMODULE_PRIVATE_HEADER = 13 +      SUBMODULE_PRIVATE_HEADER = 13, +      /// \brief Specifies a header that is part of the module but must be +      /// textually included. +      SUBMODULE_TEXTUAL_HEADER = 14, +      /// \brief Specifies a header that is private to this submodule but +      /// must be textually included. +      SUBMODULE_PRIVATE_TEXTUAL_HEADER = 15,      };      /// \brief Record types used within a comments block. @@ -759,9 +774,6 @@ namespace clang {      /// NUM_PREDEF_TYPE_IDs.      const unsigned NUM_PREDEF_TYPE_IDS = 100; -    /// \brief The number of allowed abbreviations in bits -    const unsigned NUM_ALLOWED_ABBREVS_SIZE = 4; -      /// \brief Record codes for each kind of type.      ///      /// These constants describe the type records that can occur within a @@ -1323,7 +1335,8 @@ namespace clang {        EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK,// SubstNonTypeTemplateParmPackExpr        EXPR_FUNCTION_PARM_PACK,    // FunctionParmPackExpr        EXPR_MATERIALIZE_TEMPORARY, // MaterializeTemporaryExpr -       +      EXPR_CXX_FOLD,              // CXXFoldExpr +        // CUDA        EXPR_CUDA_KERNEL_CALL,       // CUDAKernelCallExpr       @@ -1339,22 +1352,28 @@ namespace clang {        STMT_SEH_FINALLY,           // SEHFinallyStmt        STMT_SEH_TRY,               // SEHTryStmt -      // OpenMP drectives +      // OpenMP directives        STMT_OMP_PARALLEL_DIRECTIVE,        STMT_OMP_SIMD_DIRECTIVE,        STMT_OMP_FOR_DIRECTIVE, +      STMT_OMP_FOR_SIMD_DIRECTIVE,        STMT_OMP_SECTIONS_DIRECTIVE,        STMT_OMP_SECTION_DIRECTIVE,        STMT_OMP_SINGLE_DIRECTIVE,        STMT_OMP_MASTER_DIRECTIVE,        STMT_OMP_CRITICAL_DIRECTIVE,        STMT_OMP_PARALLEL_FOR_DIRECTIVE, +      STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE,        STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE,        STMT_OMP_TASK_DIRECTIVE,        STMT_OMP_TASKYIELD_DIRECTIVE,        STMT_OMP_BARRIER_DIRECTIVE,        STMT_OMP_TASKWAIT_DIRECTIVE,        STMT_OMP_FLUSH_DIRECTIVE, +      STMT_OMP_ORDERED_DIRECTIVE, +      STMT_OMP_ATOMIC_DIRECTIVE, +      STMT_OMP_TARGET_DIRECTIVE, +      STMT_OMP_TEAMS_DIRECTIVE,        // ARC        EXPR_OBJC_BRIDGED_CAST,     // ObjCBridgedCastExpr diff --git a/include/clang/Serialization/ASTDeserializationListener.h b/include/clang/Serialization/ASTDeserializationListener.h index 180f554dafea..c24ccdcd4f56 100644 --- a/include/clang/Serialization/ASTDeserializationListener.h +++ b/include/clang/Serialization/ASTDeserializationListener.h @@ -12,8 +12,8 @@  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_FRONTEND_AST_DESERIALIZATION_LISTENER_H -#define LLVM_CLANG_FRONTEND_AST_DESERIALIZATION_LISTENER_H +#ifndef LLVM_CLANG_SERIALIZATION_ASTDESERIALIZATIONLISTENER_H +#define LLVM_CLANG_SERIALIZATION_ASTDESERIALIZATIONLISTENER_H  #include "clang/Basic/IdentifierTable.h"  #include "clang/Serialization/ASTBitCodes.h" diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 3f44440d4b9a..91ad34bd1ca1 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -11,8 +11,8 @@  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_FRONTEND_AST_READER_H -#define LLVM_CLANG_FRONTEND_AST_READER_H +#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H +#define LLVM_CLANG_SERIALIZATION_ASTREADER_H  #include "clang/AST/DeclObjC.h"  #include "clang/AST/DeclarationName.h" @@ -115,7 +115,8 @@ public:    ///    /// \returns true to indicate the options are invalid or false otherwise.    virtual bool ReadLanguageOptions(const LangOptions &LangOpts, -                                   bool Complain) { +                                   bool Complain, +                                   bool AllowCompatibleDifferences) {      return false;    } @@ -193,6 +194,13 @@ public:                                bool isOverridden) {      return true;    } + +  /// \brief Returns true if this \c ASTReaderListener wants to receive the +  /// imports of the AST file via \c visitImport, false otherwise. +  virtual bool needsImportVisitation() const { return false; } +  /// \brief If needsImportVisitation returns \c true, this is called for each +  /// AST file imported by this AST file. +  virtual void visitImport(StringRef Filename) {}  };  /// \brief Simple wrapper class for chaining listeners. @@ -202,13 +210,18 @@ class ChainedASTReaderListener : public ASTReaderListener {  public:    /// Takes ownership of \p First and \p Second. -  ChainedASTReaderListener(ASTReaderListener *First, ASTReaderListener *Second) -      : First(First), Second(Second) { } +  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First, +                           std::unique_ptr<ASTReaderListener> Second) +      : First(std::move(First)), Second(std::move(Second)) {} + +  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); } +  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }    bool ReadFullVersionInformation(StringRef FullVersion) override;    void ReadModuleName(StringRef ModuleName) override;    void ReadModuleMapFile(StringRef ModuleMapPath) override; -  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain) override; +  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, +                           bool AllowCompatibleDifferences) override;    bool ReadTargetOptions(const TargetOptions &TargetOpts,                           bool Complain) override;    bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, @@ -240,8 +253,8 @@ public:    PCHValidator(Preprocessor &PP, ASTReader &Reader)      : PP(PP), Reader(Reader) {} -  bool ReadLanguageOptions(const LangOptions &LangOpts, -                           bool Complain) override; +  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, +                           bool AllowCompatibleDifferences) override;    bool ReadTargetOptions(const TargetOptions &TargetOpts,                           bool Complain) override;    bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, @@ -437,6 +450,16 @@ private:    /// \brief Declarations that have been replaced in a later file in the chain.    DeclReplacementMap ReplacedDecls; +  /// \brief Declarations that have been imported and have typedef names for +  /// linkage purposes. +  llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*> +      ImportedTypedefNamesForLinkage; + +  /// \brief Mergeable declaration contexts that have anonymous declarations +  /// within them, and those anonymous declarations. +  llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>> +    AnonymousDeclarationsForMerging; +    struct FileDeclsInfo {      ModuleFile *Mod;      ArrayRef<serialization::LocalDeclID> Decls; @@ -748,6 +771,11 @@ private:    /// at the end of the TU, in which case it directs CodeGen to emit the VTable.    SmallVector<uint64_t, 16> DynamicClasses; +  /// \brief The IDs of all potentially unused typedef names in the chain. +  /// +  /// Sema tracks these to emit warnings. +  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates; +    /// \brief The IDs of the declarations Sema stores directly.    ///    /// Sema tracks a few important decls, such as namespace std, directly. @@ -1085,12 +1113,11 @@ private:    serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,                                          bool Complain = true); -  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take -  /// into account all the necessary relocations. -  const FileEntry *getFileEntry(StringRef filename); - -  void MaybeAddSystemRootToFilename(ModuleFile &M, std::string &Filename); +public: +  void ResolveImportedPath(ModuleFile &M, std::string &Filename); +  static void ResolveImportedPath(std::string &Filename, StringRef Prefix); +private:    struct ImportedModule {      ModuleFile *Mod;      ModuleFile *ImportedBy; @@ -1106,20 +1133,25 @@ private:                              SourceLocation ImportLoc, ModuleFile *ImportedBy,                              SmallVectorImpl<ImportedModule> &Loaded,                              off_t ExpectedSize, time_t ExpectedModTime, +                            serialization::ASTFileSignature ExpectedSignature,                              unsigned ClientLoadCapabilities);    ASTReadResult ReadControlBlock(ModuleFile &F,                                   SmallVectorImpl<ImportedModule> &Loaded,                                   const ModuleFile *ImportedBy,                                   unsigned ClientLoadCapabilities);    ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities); -  bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record); +  bool ParseLineTable(ModuleFile &F, const RecordData &Record);    bool ReadSourceManagerBlock(ModuleFile &F);    llvm::BitstreamCursor &SLocCursorForID(int ID);    SourceLocation getImportLocation(ModuleFile *F); +  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, +                                       const ModuleFile *ImportedBy, +                                       unsigned ClientLoadCapabilities);    ASTReadResult ReadSubmoduleBlock(ModuleFile &F,                                     unsigned ClientLoadCapabilities);    static bool ParseLanguageOptions(const RecordData &Record, bool Complain, -                                   ASTReaderListener &Listener); +                                   ASTReaderListener &Listener, +                                   bool AllowCompatibleDifferences);    static bool ParseTargetOptions(const RecordData &Record, bool Complain,                                   ASTReaderListener &Listener);    static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain, @@ -1142,7 +1174,7 @@ private:    QualType readTypeRecord(unsigned Index);    void readExceptionSpec(ModuleFile &ModuleFile,                           SmallVectorImpl<QualType> &ExceptionStorage, -                         FunctionProtoType::ExtProtoInfo &EPI, +                         FunctionProtoType::ExceptionSpecInfo &ESI,                           const RecordData &Record, unsigned &Index);    RecordLocation TypeCursorForIndex(unsigned Index);    void LoadedDecl(unsigned Index, Decl *D); @@ -1245,6 +1277,7 @@ private:    void PassInterestingDeclToConsumer(Decl *D);    void finishPendingActions(); +  void diagnoseOdrViolations();    void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); @@ -1369,20 +1402,50 @@ public:    void makeNamesVisible(const HiddenNames &Names, Module *Owner,                          bool FromFinalization); +  /// \brief Take the AST callbacks listener. +  std::unique_ptr<ASTReaderListener> takeListener() { +    return std::move(Listener); +  } +    /// \brief Set the AST callbacks listener. -  void setListener(ASTReaderListener *listener) { -    Listener.reset(listener); +  void setListener(std::unique_ptr<ASTReaderListener> Listener) { +    this->Listener = std::move(Listener);    } -  /// \brief Add an AST callbak listener. +  /// \brief Add an AST callback listener.    ///    /// Takes ownership of \p L. -  void addListener(ASTReaderListener *L) { +  void addListener(std::unique_ptr<ASTReaderListener> L) {      if (Listener) -      L = new ChainedASTReaderListener(L, Listener.release()); -    Listener.reset(L); +      L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), +                                                      std::move(Listener)); +    Listener = std::move(L);    } +  /// RAII object to temporarily add an AST callback listener. +  class ListenerScope { +    ASTReader &Reader; +    bool Chained; + +  public: +    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L) +        : Reader(Reader), Chained(false) { +      auto Old = Reader.takeListener(); +      if (Old) { +        Chained = true; +        L = llvm::make_unique<ChainedASTReaderListener>(std::move(L), +                                                        std::move(Old)); +      } +      Reader.setListener(std::move(L)); +    } +    ~ListenerScope() { +      auto New = Reader.takeListener(); +      if (Chained) +        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get()) +                               ->takeSecond()); +    } +  }; +    /// \brief Set the AST deserialization listener.    void setDeserializationListener(ASTDeserializationListener *Listener,                                    bool TakeOwnership = false); @@ -1412,8 +1475,9 @@ public:    void UpdateSema();    /// \brief Add in-memory (virtual file) buffer. -  void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) { -    ModuleMgr.addInMemoryBuffer(FileName, Buffer); +  void addInMemoryBuffer(StringRef &FileName, +                         std::unique_ptr<llvm::MemoryBuffer> Buffer) { +    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));    }    /// \brief Finalizes the AST reader's state before writing an AST file to @@ -1772,6 +1836,9 @@ public:    void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) override; +  void ReadUnusedLocalTypedefNameCandidates( +      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; +    void ReadLocallyScopedExternCDecls(                                    SmallVectorImpl<NamedDecl *> &Decls) override; @@ -1832,17 +1899,18 @@ public:                                   ModuleFile &M, uint64_t Offset);    void installImportedMacro(IdentifierInfo *II, ModuleMacroInfo *MMI, -                            Module *Owner, bool FromFinalization); +                            Module *Owner);    typedef llvm::TinyPtrVector<DefMacroDirective *> AmbiguousMacros;    llvm::DenseMap<IdentifierInfo*, AmbiguousMacros> AmbiguousMacroDefs;    void -  removeOverriddenMacros(IdentifierInfo *II, AmbiguousMacros &Ambig, +  removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc, +                         AmbiguousMacros &Ambig,                           ArrayRef<serialization::SubmoduleID> Overrides);    AmbiguousMacros * -  removeOverriddenMacros(IdentifierInfo *II, +  removeOverriddenMacros(IdentifierInfo *II, SourceLocation Loc,                           ArrayRef<serialization::SubmoduleID> Overrides);    /// \brief Retrieve the macro with the given ID. @@ -1976,6 +2044,9 @@ public:    // \brief Read a string    static std::string ReadString(const RecordData &Record, unsigned &Idx); +  // \brief Read a path +  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx); +    /// \brief Read a version tuple.    static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx); @@ -2050,9 +2121,9 @@ public:    /// \brief Retrieve the AST context that this AST reader supplements.    ASTContext &getContext() { return Context; } -  // \brief Contains declarations that were loaded before we have +  // \brief Contains the IDs for declarations that were requested before we have    // access to a Sema object. -  SmallVector<NamedDecl *, 16> PreloadedDecls; +  SmallVector<uint64_t, 16> PreloadedDeclIDs;    /// \brief Retrieve the semantic analysis object used to analyze the    /// translation unit in which the precompiled header is being @@ -2078,6 +2149,10 @@ public:    //RIDErief Loads comments ranges.    void ReadComments() override; + +  /// Return all input files for the given module file. +  void getInputFiles(ModuleFile &F, +                     SmallVectorImpl<serialization::InputFile> &Files);  };  /// \brief Helper class that saves the current stream position and diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index ad6ecdd3519b..9907fae67654 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -11,8 +11,8 @@  //  containing a serialized representation of a translation unit.  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_FRONTEND_AST_WRITER_H -#define LLVM_CLANG_FRONTEND_AST_WRITER_H +#ifndef LLVM_CLANG_SERIALIZATION_ASTWRITER_H +#define LLVM_CLANG_SERIALIZATION_ASTWRITER_H  #include "clang/AST/ASTMutationListener.h"  #include "clang/AST/Decl.h" @@ -111,7 +111,10 @@ private:    /// \brief The module we're currently writing, if any.    Module *WritingModule; -                     + +  /// \brief The base directory for any relative paths we emit. +  std::string BaseDirectory; +    /// \brief Indicates when the AST writing is actively performing    /// serialization, rather than just queueing updates.    bool WritingAST; @@ -283,6 +286,10 @@ private:    llvm::DenseMap<const MacroDefinition *, serialization::PreprocessedEntityID>        MacroDefinitions; +  /// \brief Cache of indices of anonymous declarations within their lexical +  /// contexts. +  llvm::DenseMap<const Decl *, unsigned> AnonymousDeclarationNumbers; +    /// An update to a Decl.    class DeclUpdate {      /// A DeclUpdateKind. @@ -453,20 +460,23 @@ private:                           StringRef isysroot, const std::string &OutputFile);    void WriteInputFiles(SourceManager &SourceMgr,                         HeaderSearchOptions &HSOpts, -                       StringRef isysroot,                         bool Modules);    void WriteSourceManagerBlock(SourceManager &SourceMgr, -                               const Preprocessor &PP, -                               StringRef isysroot); +                               const Preprocessor &PP);    void WritePreprocessor(const Preprocessor &PP, bool IsModule); -  void WriteHeaderSearch(const HeaderSearch &HS, StringRef isysroot); +  void WriteHeaderSearch(const HeaderSearch &HS);    void WritePreprocessorDetail(PreprocessingRecord &PPRec);    void WriteSubmodules(Module *WritingModule);    void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,                                       bool isModule);    void WriteCXXBaseSpecifiersOffsets(); + +  unsigned TypeExtQualAbbrev; +  unsigned TypeFunctionProtoAbbrev; +  void WriteTypeAbbrevs();    void WriteType(QualType T); +    uint32_t GenerateNameLookupTable(const DeclContext *DC,                                     llvm::SmallVectorImpl<char> &LookupTable);    uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); @@ -494,17 +504,20 @@ private:    unsigned DeclContextLexicalAbbrev;    unsigned DeclContextVisibleLookupAbbrev;    unsigned UpdateVisibleAbbrev; -  unsigned DeclRefExprAbbrev; -  unsigned CharacterLiteralAbbrev;    unsigned DeclRecordAbbrev; -  unsigned IntegerLiteralAbbrev;    unsigned DeclTypedefAbbrev;    unsigned DeclVarAbbrev;    unsigned DeclFieldAbbrev;    unsigned DeclEnumAbbrev;    unsigned DeclObjCIvarAbbrev; +  unsigned DeclCXXMethodAbbrev; + +  unsigned DeclRefExprAbbrev; +  unsigned CharacterLiteralAbbrev; +  unsigned IntegerLiteralAbbrev; +  unsigned ExprImplicitCastAbbrev; -  void WriteDeclsBlockAbbrevs(); +  void WriteDeclAbbrevs();    void WriteDecl(ASTContext &Context, Decl *D);    void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record); @@ -527,7 +540,8 @@ public:    /// writing a precompiled header.    ///    /// \param isysroot if non-empty, write a relocatable file whose headers -  /// are relative to the given system root. +  /// are relative to the given system root. If we're writing a module, its +  /// build directory will be used in preference to this if both are available.    void WriteAST(Sema &SemaRef,                  const std::string &OutputFile,                  Module *WritingModule, StringRef isysroot, @@ -631,6 +645,7 @@ public:                               DeclarationName Name, RecordDataImpl &Record);    void AddDeclarationNameInfo(const DeclarationNameInfo &NameInfo,                                RecordDataImpl &Record); +  unsigned getAnonymousDeclarationNumber(const NamedDecl *D);    void AddQualifierInfo(const QualifierInfo &Info, RecordDataImpl &Record); @@ -673,6 +688,17 @@ public:    /// \brief Add a string to the given record.    void AddString(StringRef Str, RecordDataImpl &Record); +  /// \brief Convert a path from this build process into one that is appropriate +  /// for emission in the module file. +  bool PreparePathForOutput(SmallVectorImpl<char> &Path); + +  /// \brief Add a path to the given record. +  void AddPath(StringRef Path, RecordDataImpl &Record); + +  /// \brief Emit the current record with the given path as a blob. +  void EmitRecordWithPath(unsigned Abbrev, RecordDataImpl &Record, +                          StringRef Path); +    /// \brief Add a version tuple to the given record    void AddVersionTuple(const VersionTuple &Version, RecordDataImpl &Record); @@ -731,16 +757,26 @@ public:    void ClearSwitchCaseIDs(); +  unsigned getTypeExtQualAbbrev() const { +    return TypeExtQualAbbrev; +  } +  unsigned getTypeFunctionProtoAbbrev() const { +    return TypeFunctionProtoAbbrev; +  } +    unsigned getDeclParmVarAbbrev() const { return DeclParmVarAbbrev; } -  unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; } -  unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; }    unsigned getDeclRecordAbbrev() const { return DeclRecordAbbrev; } -  unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; }    unsigned getDeclTypedefAbbrev() const { return DeclTypedefAbbrev; }    unsigned getDeclVarAbbrev() const { return DeclVarAbbrev; }    unsigned getDeclFieldAbbrev() const { return DeclFieldAbbrev; }    unsigned getDeclEnumAbbrev() const { return DeclEnumAbbrev; }    unsigned getDeclObjCIvarAbbrev() const { return DeclObjCIvarAbbrev; } +  unsigned getDeclCXXMethodAbbrev() const { return DeclCXXMethodAbbrev; } + +  unsigned getDeclRefExprAbbrev() const { return DeclRefExprAbbrev; } +  unsigned getCharacterLiteralAbbrev() const { return CharacterLiteralAbbrev; } +  unsigned getIntegerLiteralAbbrev() const { return IntegerLiteralAbbrev; } +  unsigned getExprImplicitCastAbbrev() const { return ExprImplicitCastAbbrev; }    bool hasChain() const { return Chain; } @@ -775,6 +811,7 @@ public:                                      const ObjCPropertyDecl *OrigProp,                                      const ObjCCategoryDecl *ClassExt) override;    void DeclarationMarkedUsed(const Decl *D) override; +  void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;  };  /// \brief AST and semantic-analysis consumer that generates a diff --git a/include/clang/Serialization/ContinuousRangeMap.h b/include/clang/Serialization/ContinuousRangeMap.h index f8ef8a1a63cf..5f8ae1fe7bee 100644 --- a/include/clang/Serialization/ContinuousRangeMap.h +++ b/include/clang/Serialization/ContinuousRangeMap.h @@ -12,8 +12,8 @@  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_SERIALIZATION_CONTINUOUS_RANGE_MAP_H -#define LLVM_CLANG_SERIALIZATION_CONTINUOUS_RANGE_MAP_H +#ifndef LLVM_CLANG_SERIALIZATION_CONTINUOUSRANGEMAP_H +#define LLVM_CLANG_SERIALIZATION_CONTINUOUSRANGEMAP_H  #include "clang/Basic/LLVM.h"  #include "llvm/ADT/SmallVector.h" @@ -117,6 +117,14 @@ public:      ~Builder() {        std::sort(Self.Rep.begin(), Self.Rep.end(), Compare()); +      std::unique(Self.Rep.begin(), Self.Rep.end(), +                  [](const_reference A, const_reference B) { +        // FIXME: we should not allow any duplicate keys, but there are a lot of +        // duplicate 0 -> 0 mappings to remove first. +        assert((A == B || A.first != B.first) && +               "ContinuousRangeMap::Builder given non-unique keys"); +        return A == B; +      });      }      void insert(const value_type &Val) { diff --git a/include/clang/Serialization/GlobalModuleIndex.h b/include/clang/Serialization/GlobalModuleIndex.h index 1f0d7523ec29..d8a57be84a52 100644 --- a/include/clang/Serialization/GlobalModuleIndex.h +++ b/include/clang/Serialization/GlobalModuleIndex.h @@ -13,8 +13,8 @@  // queries such as "do any modules know about this identifier?"  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H -#define LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H +#ifndef LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H +#define LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H  #include "llvm/ADT/DenseMap.h"  #include "llvm/ADT/SmallPtrSet.h" @@ -115,7 +115,7 @@ class GlobalModuleIndex {    unsigned NumIdentifierLookupHits;    /// \brief Internal constructor. Use \c readIndex() to read an index. -  explicit GlobalModuleIndex(llvm::MemoryBuffer *Buffer, +  explicit GlobalModuleIndex(std::unique_ptr<llvm::MemoryBuffer> Buffer,                               llvm::BitstreamCursor Cursor);    GlobalModuleIndex(const GlobalModuleIndex &) LLVM_DELETED_FUNCTION; diff --git a/include/clang/Serialization/Module.h b/include/clang/Serialization/Module.h index 49520390559b..426cec5dd7c2 100644 --- a/include/clang/Serialization/Module.h +++ b/include/clang/Serialization/Module.h @@ -42,10 +42,11 @@ namespace reader {  /// \brief Specifies the kind of module that has been loaded.  enum ModuleKind { -  MK_Module,   ///< File is a module proper. -  MK_PCH,      ///< File is a PCH file treated as such. -  MK_Preamble, ///< File is a PCH file treated as the preamble. -  MK_MainFile  ///< File is a PCH file treated as the actual main file. +  MK_ImplicitModule, ///< File is an implicitly-loaded module. +  MK_ExplicitModule, ///< File is an explicitly-loaded module. +  MK_PCH,            ///< File is a PCH file treated as such. +  MK_Preamble,       ///< File is a PCH file treated as the preamble. +  MK_MainFile        ///< File is a PCH file treated as the actual main file.  };  /// \brief Information about the contents of a DeclContext. @@ -96,6 +97,8 @@ public:    bool isNotFound() const { return Val.getInt() == NotFound; }  }; +typedef unsigned ASTFileSignature; +  /// \brief Information about a module that has been loaded by the ASTReader.  ///  /// Each instance of the Module class corresponds to a single AST file, which @@ -122,6 +125,9 @@ public:    /// \brief The name of the module.    std::string ModuleName; +  /// \brief The base directory of the module. +  std::string BaseDirectory; +    std::string getTimestampFilename() const {      return FileName + ".timestamp";    } @@ -151,6 +157,10 @@ public:    /// \brief The file entry for the module file.    const FileEntry *File; +  /// \brief The signature of the module file, which may be used along with size +  /// and modification time to identify this particular file. +  ASTFileSignature Signature; +    /// \brief Whether this module has been directly imported by the    /// user.    bool DirectlyImported; diff --git a/include/clang/Serialization/ModuleManager.h b/include/clang/Serialization/ModuleManager.h index 3259902222d8..3d10fad0a1b6 100644 --- a/include/clang/Serialization/ModuleManager.h +++ b/include/clang/Serialization/ModuleManager.h @@ -12,8 +12,8 @@  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_SERIALIZATION_MODULE_MANAGER_H -#define LLVM_CLANG_SERIALIZATION_MODULE_MANAGER_H +#ifndef LLVM_CLANG_SERIALIZATION_MODULEMANAGER_H +#define LLVM_CLANG_SERIALIZATION_MODULEMANAGER_H  #include "clang/Basic/FileManager.h"  #include "clang/Serialization/Module.h" @@ -41,7 +41,8 @@ class ModuleManager {    FileManager &FileMgr;    /// \brief A lookup of in-memory (virtual file) buffers -  llvm::DenseMap<const FileEntry *, llvm::MemoryBuffer *> InMemoryBuffers; +  llvm::DenseMap<const FileEntry *, std::unique_ptr<llvm::MemoryBuffer>> +      InMemoryBuffers;    /// \brief The visitation order.    SmallVector<ModuleFile *, 4> VisitOrder; @@ -141,7 +142,7 @@ public:    ModuleFile *lookup(const FileEntry *File);    /// \brief Returns the in-memory (virtual file) buffer with the given name -  llvm::MemoryBuffer *lookupBuffer(StringRef Name); +  std::unique_ptr<llvm::MemoryBuffer> lookupBuffer(StringRef Name);    /// \brief Number of modules loaded    unsigned size() const { return Chain.size(); } @@ -178,6 +179,12 @@ public:    /// \param ExpectedModTime The expected modification time of the module    /// file, used for validation. This will be zero if unknown.    /// +  /// \param ExpectedSignature The expected signature of the module file, used +  /// for validation. This will be zero if unknown. +  /// +  /// \param ReadSignature Reads the signature from an AST file without actually +  /// loading it. +  ///    /// \param Module A pointer to the module file if the module was successfully    /// loaded.    /// @@ -190,6 +197,9 @@ public:                              SourceLocation ImportLoc,                              ModuleFile *ImportedBy, unsigned Generation,                              off_t ExpectedSize, time_t ExpectedModTime, +                            ASTFileSignature ExpectedSignature, +                            std::function<ASTFileSignature(llvm::BitstreamReader &)> +                                ReadSignature,                              ModuleFile *&Module,                              std::string &ErrorStr); @@ -199,7 +209,8 @@ public:                       ModuleMap *modMap);    /// \brief Add an in-memory buffer the list of known buffers -  void addInMemoryBuffer(StringRef FileName, llvm::MemoryBuffer *Buffer); +  void addInMemoryBuffer(StringRef FileName, +                         std::unique_ptr<llvm::MemoryBuffer> Buffer);    /// \brief Set the global module index.    void setGlobalIndex(GlobalModuleIndex *Index); @@ -232,7 +243,7 @@ public:    /// Any module that is known to both the global module index and the module    /// manager that is *not* in this set can be skipped.    void visit(bool (*Visitor)(ModuleFile &M, void *UserData), void *UserData, -             llvm::SmallPtrSet<ModuleFile *, 4> *ModuleFilesHit = nullptr); +             llvm::SmallPtrSetImpl<ModuleFile *> *ModuleFilesHit = nullptr);    /// \brief Visit each of the modules with a depth-first traversal.    /// diff --git a/include/clang/Serialization/SerializationDiagnostic.h b/include/clang/Serialization/SerializationDiagnostic.h index c28cfea25c87..d50422aa466c 100644 --- a/include/clang/Serialization/SerializationDiagnostic.h +++ b/include/clang/Serialization/SerializationDiagnostic.h @@ -7,8 +7,8 @@  //  //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_SERIALIZATIONDIAGNOSTIC_H -#define LLVM_CLANG_SERIALIZATIONDIAGNOSTIC_H +#ifndef LLVM_CLANG_SERIALIZATION_SERIALIZATIONDIAGNOSTIC_H +#define LLVM_CLANG_SERIALIZATION_SERIALIZATIONDIAGNOSTIC_H  #include "clang/Basic/Diagnostic.h"  | 
