clang  14.0.0git
Functions
CompilerInstance.cpp File Reference
#include "clang/Frontend/CompilerInstance.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/Stack.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Frontend/ChainedDiagnosticConsumer.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Frontend/LogDiagnosticPrinter.h"
#include "clang/Frontend/SerializedDiagnosticPrinter.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/Utils.h"
#include "clang/Frontend/VerifyDiagnosticConsumer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/GlobalModuleIndex.h"
#include "clang/Serialization/InMemoryModuleCache.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/BuryPointer.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/LockFileManager.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include <time.h>
#include <utility>
Include dependency graph for CompilerInstance.cpp:

Go to the source code of this file.

Functions

static void collectHeaderMaps (const HeaderSearch &HS, std::shared_ptr< ModuleDependencyCollector > MDC)
 
static void collectIncludePCH (CompilerInstance &CI, std::shared_ptr< ModuleDependencyCollector > MDC)
 
static void collectVFSEntries (CompilerInstance &CI, std::shared_ptr< ModuleDependencyCollector > MDC)
 
static void SetUpDiagnosticLog (DiagnosticOptions *DiagOpts, const CodeGenOptions *CodeGenOpts, DiagnosticsEngine &Diags)
 
static void SetupSerializedDiagnostics (DiagnosticOptions *DiagOpts, DiagnosticsEngine &Diags, StringRef OutputFile)
 
static void InitializeFileRemapping (DiagnosticsEngine &Diags, SourceManager &SourceMgr, FileManager &FileMgr, const PreprocessorOptions &InitOpts)
 
static bool EnableCodeCompletion (Preprocessor &PP, StringRef Filename, unsigned Line, unsigned Column)
 
static Language getLanguageFromOptions (const LangOptions &LangOpts)
 Determine the appropriate source input kind based on language options. More...
 
static bool compileModuleImpl (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input, StringRef OriginalModuleMapFile, StringRef ModuleFileName, llvm::function_ref< void(CompilerInstance &)> PreBuildStep=[](CompilerInstance &) {}, llvm::function_ref< void(CompilerInstance &)> PostBuildStep=[](CompilerInstance &) {})
 Compile a module file for the given module, using the options provided by the importing compiler instance. More...
 
static const FileEntrygetPublicModuleMap (const FileEntry *File, FileManager &FileMgr)
 
static bool compileModule (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName)
 Compile a module file for the given module in a separate compiler instance, using the options provided by the importing compiler instance. More...
 
static bool readASTAfterCompileModule (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName, bool *OutOfDate)
 Read the AST right after compiling the module. More...
 
static bool compileModuleAndReadASTImpl (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)
 Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors. More...
 
static bool compileModuleAndReadASTBehindLock (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)
 Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors, using a lock manager to avoid building the same module in multiple compiler instances. More...
 
static bool compileModuleAndReadAST (CompilerInstance &ImportingInstance, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, Module *Module, StringRef ModuleFileName)
 Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors, potentially using a lock manager to avoid building the same module in multiple compiler instances. More...
 
static void checkConfigMacro (Preprocessor &PP, StringRef ConfigMacro, Module *Mod, SourceLocation ImportLoc)
 Diagnose differences between the current definition of the given configuration macro and the definition provided on the command line. More...
 
static void writeTimestampFile (StringRef TimestampFile)
 Write a new timestamp file with the given path. More...
 
static void pruneModuleCache (const HeaderSearchOptions &HSOpts)
 Prune the module cache of modules that haven't been accessed in a long time. More...
 
static ModuleSource selectModuleSource (Module *M, StringRef ModuleName, std::string &ModuleFilename, const std::map< std::string, std::string, std::less<>> &BuiltModules, HeaderSearch &HS)
 Select a source for loading the named module and compute the filename to load it from. More...
 

Function Documentation

◆ checkConfigMacro()

static void checkConfigMacro ( Preprocessor PP,
StringRef  ConfigMacro,
Module Mod,
SourceLocation  ImportLoc 
)
static

◆ collectHeaderMaps()

static void collectHeaderMaps ( const HeaderSearch HS,
std::shared_ptr< ModuleDependencyCollector MDC 
)
static

◆ collectIncludePCH()

static void collectIncludePCH ( CompilerInstance CI,
std::shared_ptr< ModuleDependencyCollector MDC 
)
static

◆ collectVFSEntries()

static void collectVFSEntries ( CompilerInstance CI,
std::shared_ptr< ModuleDependencyCollector MDC 
)
static

◆ compileModule()

static bool compileModule ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
Module Module,
StringRef  ModuleFileName 
)
static

◆ compileModuleAndReadAST()

static bool compileModuleAndReadAST ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
SourceLocation  ModuleNameLoc,
Module Module,
StringRef  ModuleFileName 
)
static

Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors, potentially using a lock manager to avoid building the same module in multiple compiler instances.

Definition at line 1474 of file CompilerInstance.cpp.

References clang::FrontendOptions::BuildingImplicitModuleUsesLock, compileModuleAndReadASTBehindLock(), compileModuleAndReadASTImpl(), clang::CompilerInvocationValueBase::getFrontendOpts(), and clang::CompilerInstance::getInvocation().

◆ compileModuleAndReadASTBehindLock()

static bool compileModuleAndReadASTBehindLock ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
SourceLocation  ModuleNameLoc,
Module Module,
StringRef  ModuleFileName 
)
static

Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors, using a lock manager to avoid building the same module in multiple compiler instances.

Uses a lock file manager and exponential backoff to reduce the chances that multiple instances will compete to create the same module. On timeout, deletes the lock file in order to avoid deadlock from crashing processes or bugs in the lock file manager.

Definition at line 1404 of file CompilerInstance.cpp.

References compileModuleAndReadASTImpl(), clang::CompilerInstance::getDiagnostics(), clang::Module::Name, readASTAfterCompileModule(), and clang::DiagnosticsEngine::Report().

Referenced by compileModuleAndReadAST().

◆ compileModuleAndReadASTImpl()

static bool compileModuleAndReadASTImpl ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
SourceLocation  ModuleNameLoc,
Module Module,
StringRef  ModuleFileName 
)
static

Compile a module in a separate compiler instance and read the AST, returning true if the module compiles without errors.

Definition at line 1378 of file CompilerInstance.cpp.

References compileModule(), clang::CompilerInstance::getDiagnostics(), clang::Module::Name, readASTAfterCompileModule(), and clang::DiagnosticsEngine::Report().

Referenced by compileModuleAndReadAST(), and compileModuleAndReadASTBehindLock().

◆ compileModuleImpl()

static bool compileModuleImpl ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
StringRef  ModuleName,
FrontendInputFile  Input,
StringRef  OriginalModuleMapFile,
StringRef  ModuleFileName,
llvm::function_ref< void(CompilerInstance &)>  PreBuildStep = [](CompilerInstance &) {},
llvm::function_ref< void(CompilerInstance &)>  PostBuildStep = [](CompilerInstance &) {} 
)
static

Compile a module file for the given module, using the options provided by the importing compiler instance.

Returns true if the module was built without errors.

Definition at line 1125 of file CompilerInstance.cpp.

Referenced by compileModule(), and clang::CompilerInstance::createModuleFromSource().

◆ EnableCodeCompletion()

static bool EnableCodeCompletion ( Preprocessor PP,
StringRef  Filename,
unsigned  Line,
unsigned  Column 
)
static

◆ getLanguageFromOptions()

static Language getLanguageFromOptions ( const LangOptions LangOpts)
static

Determine the appropriate source input kind based on language options.

Definition at line 1111 of file CompilerInstance.cpp.

References clang::C, clang::CUDA, clang::CXX, clang::ObjC, clang::ObjCXX, and clang::OpenCL.

Referenced by compileModule(), and clang::CompilerInstance::createModuleFromSource().

◆ getPublicModuleMap()

static const FileEntry* getPublicModuleMap ( const FileEntry File,
FileManager FileMgr 
)
static

Definition at line 1262 of file CompilerInstance.cpp.

References clang::File, Filename, and clang::FileManager::getFile().

Referenced by compileModule().

◆ InitializeFileRemapping()

static void InitializeFileRemapping ( DiagnosticsEngine Diags,
SourceManager SourceMgr,
FileManager FileMgr,
const PreprocessorOptions InitOpts 
)
static

◆ pruneModuleCache()

static void pruneModuleCache ( const HeaderSearchOptions HSOpts)
static

◆ readASTAfterCompileModule()

static bool readASTAfterCompileModule ( CompilerInstance ImportingInstance,
SourceLocation  ImportLoc,
SourceLocation  ModuleNameLoc,
Module Module,
StringRef  ModuleFileName,
bool OutOfDate 
)
static

◆ selectModuleSource()

static ModuleSource selectModuleSource ( Module M,
StringRef  ModuleName,
std::string ModuleFilename,
const std::map< std::string, std::string, std::less<>> &  BuiltModules,
HeaderSearch HS 
)
static

◆ SetUpDiagnosticLog()

static void SetUpDiagnosticLog ( DiagnosticOptions DiagOpts,
const CodeGenOptions CodeGenOpts,
DiagnosticsEngine Diags 
)
static

◆ SetupSerializedDiagnostics()

static void SetupSerializedDiagnostics ( DiagnosticOptions DiagOpts,
DiagnosticsEngine Diags,
StringRef  OutputFile 
)
static

◆ writeTimestampFile()

static void writeTimestampFile ( StringRef  TimestampFile)
static

Write a new timestamp file with the given path.

Definition at line 1548 of file CompilerInstance.cpp.

Referenced by pruneModuleCache().