clang  6.0.0svn
Classes | Namespaces | Macros | Functions
ASTReader.cpp File Reference
#include "clang/Serialization/ASTReader.h"
#include "ASTCommon.h"
#include "ASTReaderInternals.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/ASTUnresolvedSet.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/ODRHash.h"
#include "clang/AST/RawCommentList.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLocVisitor.h"
#include "clang/AST/UnresolvedSet.h"
#include "clang/Basic/CommentOptions.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/MemoryBufferCache.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/OperatorKinds.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/Version.h"
#include "clang/Basic/VersionTuple.h"
#include "clang/Frontend/PCHContainerOperations.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/ModuleMap.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/Weak.h"
#include "clang/Serialization/ASTDeserializationListener.h"
#include "clang/Serialization/GlobalModuleIndex.h"
#include "clang/Serialization/ModuleManager.h"
#include "clang/Serialization/SerializationDiagnostic.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <new>
#include <string>
#include <system_error>
#include <tuple>
#include <utility>
#include <vector>
#include "clang/Basic/LangOptions.def"
#include "clang/Basic/Sanitizers.def"
#include "clang/Basic/DiagnosticOptions.def"
#include "clang/AST/TypeLocNodes.def"
#include "clang/Basic/OpenCLImageTypes.def"

Go to the source code of this file.

Classes

class  clang::TypeLocReader
 
class  clang::ASTIdentifierIterator
 An identifier-lookup iterator that enumerates all of the identifiers stored within a set of AST files. More...
 
class  clang::serialization::ReadMethodPoolVisitor
 

Namespaces

 clang
 Dataflow Directional Tag Classes.
 
 clang::serialization
 

Macros

#define LANGOPT(Name, Bits, Default, Description)
 
#define VALUE_LANGOPT(Name, Bits, Default, Description)
 
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
 
#define COMPATIBLE_LANGOPT(Name, Bits, Default, Description)
 
#define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description)
 
#define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description)
 
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
 
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
 
#define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description)
 
#define SANITIZER(NAME, ID)
 
#define CHECK_TARGET_OPT(Field, Name)
 
#define LANGOPT(Name, Bits, Default, Description)   LangOpts.Name = Record[Idx++];
 
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)   LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));
 
#define SANITIZER(NAME, ID)   LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]);
 
#define DIAGOPT(Name, Bits, Default)   DiagOpts->Name = Record[Idx++];
 
#define ENUM_DIAGOPT(Name, Type, Bits, Default)   DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));
 
#define ABSTRACT_TYPELOC(CLASS, PARENT)
 
#define TYPELOC(CLASS, PARENT)   void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
 
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)
 

Functions

static bool checkLanguageOptions (const LangOptions &LangOpts, const LangOptions &ExistingLangOpts, DiagnosticsEngine *Diags, bool AllowCompatibleDifferences=true)
 Compare the given set of language options against an existing set of language options. More...
 
static bool checkTargetOptions (const TargetOptions &TargetOpts, const TargetOptions &ExistingTargetOpts, DiagnosticsEngine *Diags, bool AllowCompatibleDifferences=true)
 Compare the given set of target options against an existing set of target options. More...
 
static bool checkDiagnosticGroupMappings (DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool Complain)
 
static bool isExtHandlingFromDiagsError (DiagnosticsEngine &Diags)
 
static bool checkDiagnosticMappings (DiagnosticsEngine &StoredDiags, DiagnosticsEngine &Diags, bool IsSystem, bool Complain)
 
static ModulegetTopImportImplicitModule (ModuleManager &ModuleMgr, Preprocessor &PP)
 Return the top import module if it is implicit, nullptr otherwise. More...
 
static void collectMacroDefinitions (const PreprocessorOptions &PPOpts, MacroDefinitionsMap &Macros, SmallVectorImpl< StringRef > *MacroNames=nullptr)
 Collect the macro definitions provided by the given preprocessor options. More...
 
static bool checkPreprocessorOptions (const PreprocessorOptions &PPOpts, const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags, FileManager &FileMgr, std::string &SuggestedPredefines, const LangOptions &LangOpts, bool Validate=true)
 Check the preprocessor options deserialized from the control block against the preprocessor options in an existing preprocessor. More...
 
static bool checkHeaderSearchOptions (const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, StringRef ExistingModuleCachePath, DiagnosticsEngine *Diags, const LangOptions &LangOpts)
 Check the header search options deserialized from the control block against the header search options in an existing preprocessor. More...
 
static bool isInterestingIdentifier (ASTReader &Reader, IdentifierInfo &II, bool IsModule)
 Whether the given identifier is "interesting". More...
 
static bool readBit (unsigned &Bits)
 
static void markIdentifierFromAST (ASTReader &Reader, IdentifierInfo &II)
 
static std::string resolveFileRelativeToOriginalDir (const std::string &Filename, const std::string &OriginalDir, const std::string &CurrDir)
 If a header file is not found at the path that we expect it to be and the PCH file was moved from its original location, try to resolve the file by assuming that header+PCH were moved together and the header is in the same place relative to the PCH. More...
 
static unsigned moduleKindForDiagnostic (ModuleKind Kind)
 
static bool isDiagnosedResult (ASTReader::ASTReadResult ARR, unsigned Caps)
 
static void moveMethodToBackOfGlobalList (Sema &S, ObjCMethodDecl *Method)
 Move the given method to the back of the global list of methods. More...
 
static void updateModuleTimestamp (ModuleFile &MF)
 
static bool SkipCursorToBlock (BitstreamCursor &Cursor, unsigned BlockID)
 Given a cursor at the start of an AST file, scan ahead and drop the cursor into the start of the given block ID, returning false on success and true on failure. More...
 
static ASTFileSignature readASTFileSignature (StringRef PCH)
 Reads and return the signature record from PCH's control block, or else returns 0. More...
 
static bool startsWithASTFileMagic (BitstreamCursor &Stream)
 Whether Stream starts with the AST/PCH file magic number 'CPCH'. More...
 
static bool parseModuleFileExtensionMetadata (const SmallVectorImpl< uint64_t > &Record, StringRef Blob, ModuleFileExtensionMetadata &Metadata)
 Parse a record and blob containing module file extension metadata. More...
 
static DeclgetPredefinedDecl (ASTContext &Context, PredefinedDeclIDs ID)
 
static void PassObjCImplDeclToConsumer (ObjCImplDecl *ImplD, ASTConsumer *Consumer)
 Under non-PCH compilation the consumer receives the objc methods before receiving the implementation, and codegen depends on this. More...
 
template<typename Key , typename ModuleFile , unsigned InitialCapacity>
static LLVM_DUMP_METHOD void dumpModuleIDMap (StringRef Name, const ContinuousRangeMap< Key, ModuleFile *, InitialCapacity > &Map)
 
static void addMethodsToPool (Sema &S, ArrayRef< ObjCMethodDecl *> Methods, ObjCMethodList &List)
 Add the given set of methods to the method list. More...
 

Macro Definition Documentation

◆ ABSTRACT_TYPELOC

#define ABSTRACT_TYPELOC (   CLASS,
  PARENT 
)

Definition at line 6338 of file ASTReader.cpp.

◆ BENIGN_ENUM_LANGOPT

#define BENIGN_ENUM_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)

◆ BENIGN_LANGOPT

#define BENIGN_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)

◆ BENIGN_VALUE_LANGOPT

#define BENIGN_VALUE_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)

◆ CHECK_TARGET_OPT

#define CHECK_TARGET_OPT (   Field,
  Name 
)
Value:
if (TargetOpts.Field != ExistingTargetOpts.Field) { \
if (Diags) \
Diags->Report(diag::err_pch_targetopt_mismatch) \
<< Name << TargetOpts.Field << ExistingTargetOpts.Field; \
return true; \
}

Referenced by checkTargetOptions().

◆ COMPATIBLE_ENUM_LANGOPT

#define COMPATIBLE_ENUM_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
Value:
if (!AllowCompatibleDifferences) \
ENUM_LANGOPT(Name, Bits, Default, Description)

◆ COMPATIBLE_LANGOPT

#define COMPATIBLE_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
Value:
if (!AllowCompatibleDifferences) \
LANGOPT(Name, Bits, Default, Description)

◆ COMPATIBLE_VALUE_LANGOPT

#define COMPATIBLE_VALUE_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
Value:
if (!AllowCompatibleDifferences) \
VALUE_LANGOPT(Name, Bits, Default, Description)

◆ DIAGOPT

#define DIAGOPT (   Name,
  Bits,
  Default 
)    DiagOpts->Name = Record[Idx++];

◆ ENUM_DIAGOPT

#define ENUM_DIAGOPT (   Name,
  Type,
  Bits,
  Default 
)    DiagOpts->set##Name(static_cast<Type>(Record[Idx++]));

◆ ENUM_LANGOPT [1/2]

#define ENUM_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)
Value:
if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \
if (Diags) \
Diags->Report(diag::err_pch_langopt_value_mismatch) \
<< Description; \
return true; \
}

◆ ENUM_LANGOPT [2/2]

#define ENUM_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)    LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++]));

◆ IMAGE_TYPE

#define IMAGE_TYPE (   ImgType,
  Id,
  SingletonId,
  Access,
  Suffix 
)
Value:
case PREDEF_TYPE_##Id##_ID: \
T = Context.SingletonId; \
break;
int Id
Definition: ASTDiff.cpp:191

◆ LANGOPT [1/2]

#define LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
Value:
if (ExistingLangOpts.Name != LangOpts.Name) { \
if (Diags) \
Diags->Report(diag::err_pch_langopt_mismatch) \
<< Description << LangOpts.Name << ExistingLangOpts.Name; \
return true; \
}

◆ LANGOPT [2/2]

#define LANGOPT (   Name,
  Bits,
  Default,
  Description 
)    LangOpts.Name = Record[Idx++];

◆ SANITIZER [1/2]

#define SANITIZER (   NAME,
  ID 
)
Value:
{ \
bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \
bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \
if (InExistingModule != InImportedModule) \
Diags->Report(diag::err_pch_targetopt_feature_mismatch) \
<< InExistingModule << (Flag + NAME); \
}

◆ SANITIZER [2/2]

#define SANITIZER (   NAME,
  ID 
)    LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]);

◆ TYPELOC

#define TYPELOC (   CLASS,
  PARENT 
)    void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);

Definition at line 6339 of file ASTReader.cpp.

◆ VALUE_LANGOPT

#define VALUE_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
Value:
if (ExistingLangOpts.Name != LangOpts.Name) { \
if (Diags) \
Diags->Report(diag::err_pch_langopt_value_mismatch) \
<< Description; \
return true; \
}

Function Documentation

◆ addMethodsToPool()

static void addMethodsToPool ( Sema S,
ArrayRef< ObjCMethodDecl *>  Methods,
ObjCMethodList List 
)
static

Add the given set of methods to the method list.

Definition at line 7864 of file ASTReader.cpp.

◆ checkDiagnosticGroupMappings()

static bool checkDiagnosticGroupMappings ( DiagnosticsEngine StoredDiags,
DiagnosticsEngine Diags,
bool  Complain 
)
static

◆ checkDiagnosticMappings()

static bool checkDiagnosticMappings ( DiagnosticsEngine StoredDiags,
DiagnosticsEngine Diags,
bool  IsSystem,
bool  Complain 
)
static

◆ checkHeaderSearchOptions()

static bool checkHeaderSearchOptions ( const HeaderSearchOptions HSOpts,
StringRef  SpecificModuleCachePath,
StringRef  ExistingModuleCachePath,
DiagnosticsEngine Diags,
const LangOptions LangOpts 
)
static

Check the header search options deserialized from the control block against the header search options in an existing preprocessor.

Parameters
DiagsIf non-null, produce diagnostics for any mismatches incurred.

Definition at line 726 of file ASTReader.cpp.

References clang::DiagnosticsEngine::Report().

Referenced by clang::PCHValidator::ReadHeaderSearchOptions().

◆ checkLanguageOptions()

static bool checkLanguageOptions ( const LangOptions LangOpts,
const LangOptions ExistingLangOpts,
DiagnosticsEngine Diags,
bool  AllowCompatibleDifferences = true 
)
static

Compare the given set of language options against an existing set of language options.

Parameters
DiagsIf non-NULL, diagnostics will be emitted via this engine.
AllowCompatibleDifferencesIf true, differences between compatible language options will be permitted.
Returns
true if the languagae options mis-match, false otherwise.

Definition at line 229 of file ASTReader.cpp.

References clang::CommentOptions::BlockCommandNames, clang::SanitizerSet::clear(), clang::LangOptions::CommentOpts, clang::getPPTransparentSanitizers(), clang::SanitizerSet::Mask, clang::LangOptions::ModuleFeatures, clang::LangOptions::ObjCRuntime, clang::DiagnosticsEngine::Report(), and clang::LangOptions::Sanitize.

Referenced by clang::PCHValidator::ReadLanguageOptions().

◆ checkPreprocessorOptions()

static bool checkPreprocessorOptions ( const PreprocessorOptions PPOpts,
const PreprocessorOptions ExistingPPOpts,
DiagnosticsEngine Diags,
FileManager FileMgr,
std::string &  SuggestedPredefines,
const LangOptions LangOpts,
bool  Validate = true 
)
static

Check the preprocessor options deserialized from the control block against the preprocessor options in an existing preprocessor.

Parameters
DiagsIf non-null, produce diagnostics for any mismatches incurred.
ValidateIf true, validate preprocessor options. If false, allow macros defined by ExistingPPOpts to override those defined by PPOpts in SuggestedPredefines.

Definition at line 586 of file ASTReader.cpp.

References collectMacroDefinitions().

Referenced by clang::PCHValidator::ReadPreprocessorOptions(), and clang::SimpleASTReaderListener::ReadPreprocessorOptions().

◆ checkTargetOptions()

static bool checkTargetOptions ( const TargetOptions TargetOpts,
const TargetOptions ExistingTargetOpts,
DiagnosticsEngine Diags,
bool  AllowCompatibleDifferences = true 
)
static

Compare the given set of target options against an existing set of target options.

Parameters
DiagsIf non-NULL, diagnostics will be emitted via this engine.
Returns
true if the target options mis-match, false otherwise.

Definition at line 331 of file ASTReader.cpp.

References CHECK_TARGET_OPT, clang::TargetOptions::FeaturesAsWritten, and clang::DiagnosticsEngine::Report().

Referenced by clang::PCHValidator::ReadTargetOptions().

◆ collectMacroDefinitions()

static void collectMacroDefinitions ( const PreprocessorOptions PPOpts,
MacroDefinitionsMap &  Macros,
SmallVectorImpl< StringRef > *  MacroNames = nullptr 
)
static

Collect the macro definitions provided by the given preprocessor options.

Definition at line 544 of file ASTReader.cpp.

Referenced by checkPreprocessorOptions().

◆ dumpModuleIDMap()

template<typename Key , typename ModuleFile , unsigned InitialCapacity>
static LLVM_DUMP_METHOD void dumpModuleIDMap ( StringRef  Name,
const ContinuousRangeMap< Key, ModuleFile *, InitialCapacity > &  Map 
)
static

Definition at line 7511 of file ASTReader.cpp.

Referenced by clang::ASTReader::dump().

◆ getPredefinedDecl()

static Decl* getPredefinedDecl ( ASTContext Context,
PredefinedDeclIDs  ID 
)
static

Definition at line 7056 of file ASTReader.cpp.

Referenced by clang::ASTReader::GetExistingDecl().

◆ getTopImportImplicitModule()

static Module* getTopImportImplicitModule ( ModuleManager ModuleMgr,
Preprocessor PP 
)
static

◆ isDiagnosedResult()

static bool isDiagnosedResult ( ASTReader::ASTReadResult  ARR,
unsigned  Caps 
)
static

◆ isExtHandlingFromDiagsError()

static bool isExtHandlingFromDiagsError ( DiagnosticsEngine Diags)
static

◆ isInterestingIdentifier()

static bool isInterestingIdentifier ( ASTReader Reader,
IdentifierInfo II,
bool  IsModule 
)
static

◆ markIdentifierFromAST()

static void markIdentifierFromAST ( ASTReader Reader,
IdentifierInfo II 
)
static

◆ moduleKindForDiagnostic()

static unsigned moduleKindForDiagnostic ( ModuleKind  Kind)
static

◆ moveMethodToBackOfGlobalList()

static void moveMethodToBackOfGlobalList ( Sema S,
ObjCMethodDecl Method 
)
static

Move the given method to the back of the global list of methods.

Definition at line 3594 of file ASTReader.cpp.

Referenced by clang::ASTReader::makeNamesVisible().

◆ parseModuleFileExtensionMetadata()

static bool parseModuleFileExtensionMetadata ( const SmallVectorImpl< uint64_t > &  Record,
StringRef  Blob,
ModuleFileExtensionMetadata Metadata 
)
static

◆ PassObjCImplDeclToConsumer()

static void PassObjCImplDeclToConsumer ( ObjCImplDecl ImplD,
ASTConsumer Consumer 
)
static

Under non-PCH compilation the consumer receives the objc methods before receiving the implementation, and codegen depends on this.

We simulate this by deserializing and passing to consumer the methods of the implementation before passing the deserialized implementation decl.

Definition at line 7383 of file ASTReader.cpp.

◆ readASTFileSignature()

static ASTFileSignature readASTFileSignature ( StringRef  PCH)
static

Reads and return the signature record from PCH's control block, or else returns 0.

Definition at line 4507 of file ASTReader.cpp.

References clang::serialization::SIGNATURE, SkipCursorToBlock(), startsWithASTFileMagic(), and clang::serialization::UNHASHED_CONTROL_BLOCK_ID.

◆ readBit()

static bool readBit ( unsigned &  Bits)
static

◆ resolveFileRelativeToOriginalDir()

static std::string resolveFileRelativeToOriginalDir ( const std::string &  Filename,
const std::string &  OriginalDir,
const std::string &  CurrDir 
)
static

If a header file is not found at the path that we expect it to be and the PCH file was moved from its original location, try to resolve the file by assuming that header+PCH were moved together and the header is in the same place relative to the PCH.

Definition at line 1276 of file ASTReader.cpp.

◆ SkipCursorToBlock()

static bool SkipCursorToBlock ( BitstreamCursor &  Cursor,
unsigned  BlockID 
)
static

Given a cursor at the start of an AST file, scan ahead and drop the cursor into the start of the given block ID, returning false on success and true on failure.

Definition at line 3749 of file ASTReader.cpp.

References clang::serialized_diags::Error.

Referenced by readASTFileSignature().

◆ startsWithASTFileMagic()

static bool startsWithASTFileMagic ( BitstreamCursor &  Stream)
static

Whether Stream starts with the AST/PCH file magic number 'CPCH'.

Definition at line 4014 of file ASTReader.cpp.

Referenced by readASTFileSignature().

◆ updateModuleTimestamp()

static void updateModuleTimestamp ( ModuleFile MF)
static