clang 17.0.0git
|
Helper class for holding the data necessary to invoke the compiler. More...
#include "clang/Frontend/CompilerInvocation.h"
Public Types | |
using | StringAllocator = llvm::function_ref< const char *(const llvm::Twine &)> |
Static Public Member Functions | |
static bool | CreateFromArgs (CompilerInvocation &Res, ArrayRef< const char * > CommandLineArgs, DiagnosticsEngine &Diags, const char *Argv0=nullptr) |
Create a compiler invocation from a list of input options. | |
static std::string | GetResourcesPath (const char *Argv0, void *MainAddr) |
Get the directory where the compiler headers reside, relative to the compiler binary (found by the passed in arguments). | |
static bool | checkCC1RoundTrip (ArrayRef< const char * > Args, DiagnosticsEngine &Diags, const char *Argv0=nullptr) |
Check that Args can be parsed and re-serialized without change, emiting diagnostics for any differences. | |
Additional Inherited Members | |
![]() | |
std::shared_ptr< LangOptions > | LangOpts |
Options controlling the language variant. | |
std::shared_ptr< TargetOptions > | TargetOpts |
Options controlling the target. | |
IntrusiveRefCntPtr< DiagnosticOptions > | DiagnosticOpts |
Options controlling the diagnostic engine. | |
std::shared_ptr< HeaderSearchOptions > | HeaderSearchOpts |
Options controlling the #include directive. | |
std::shared_ptr< PreprocessorOptions > | PreprocessorOpts |
Options controlling the preprocessor (aside from #include handling). | |
AnalyzerOptionsRef | AnalyzerOpts |
Options controlling the static analyzer. | |
![]() | |
MigratorOptions | MigratorOpts |
CodeGenOptions | CodeGenOpts |
Options controlling IRgen and the backend. | |
DependencyOutputOptions | DependencyOutputOpts |
Options controlling dependency output. | |
FileSystemOptions | FileSystemOpts |
Options controlling file system operations. | |
FrontendOptions | FrontendOpts |
Options controlling the frontend itself. | |
PreprocessorOutputOptions | PreprocessorOutputOpts |
Options controlling preprocessed output. | |
Helper class for holding the data necessary to invoke the compiler.
This class is designed to represent an abstract "invocation" of the compiler, including data such as the include paths, the code generation options, the warning flags, and so on.
Definition at line 193 of file CompilerInvocation.h.
using clang::CompilerInvocation::StringAllocator = llvm::function_ref<const char *(const llvm::Twine &)> |
Definition at line 226 of file CompilerInvocation.h.
|
static |
Check that Args
can be parsed and re-serialized without change, emiting diagnostics for any differences.
This check is only suitable for command-lines that are expected to already be canonical.
Definition at line 798 of file CompilerInvocation.cpp.
References generateCC1CommandLine(), and RoundTrip().
void CompilerInvocation::clearImplicitModuleBuildOptions | ( | ) |
Disable implicit modules and canonicalize options that are only used by implicit modules.
so use the default values so they may be dropped from the command-line.
Definition at line 4639 of file CompilerInvocation.cpp.
References clang::HeaderSearchOptions::BuildSessionTimestamp, clang::CompilerInvocationRefBase::getHeaderSearchOpts(), clang::CompilerInvocationRefBase::getLangOpts(), clang::HeaderSearchOptions::ImplicitModuleMaps, clang::HeaderSearchOptions::ModuleCachePath, clang::HeaderSearchOptions::ModuleCachePruneAfter, clang::HeaderSearchOptions::ModuleCachePruneInterval, and clang::HeaderSearchOptions::ModulesValidateOncePerBuildSession.
Referenced by clang::tooling::dependencies::ModuleDepCollector::applyDiscoveredDependencies().
|
static |
Create a compiler invocation from a list of input options.
Res
will end up in one of the vaild-to-access (albeit arbitrary) states.[out] | Res | - The resulting invocation. |
[in] | CommandLineArgs | - Array of argument strings, this must not contain "-cc1". |
Definition at line 4484 of file CompilerInvocation.cpp.
References generateCC1CommandLine(), and RoundTrip().
Referenced by clang::createInvocation(), main(), clang::tooling::newInvocation(), and clang::TestAST::TestAST().
void CompilerInvocation::generateCC1CommandLine | ( | llvm::SmallVectorImpl< const char * > & | Args, |
StringAllocator | SA | ||
) | const |
Generate cc1-compatible command line arguments from this instance.
[out] | Args | - The generated arguments. Note that the caller is responsible for inserting the path to the clang executable and "-cc1" if desired. |
SA | - A function that given a Twine can allocate storage for a given command line argument and return a pointer to the newly allocated string. The returned pointer is what gets appended to Args. |
Definition at line 4599 of file CompilerInvocation.cpp.
References clang::CompilerInvocationRefBase::AnalyzerOpts, clang::CompilerInvocationValueBase::CodeGenOpts, clang::FrontendOptions::DashX, clang::CompilerInvocationValueBase::DependencyOutputOpts, clang::CompilerInvocationRefBase::DiagnosticOpts, clang::CompilerInvocationValueBase::FileSystemOpts, clang::CompilerInvocationValueBase::FrontendOpts, GenerateAnalyzerArgs(), GenerateDependencyOutputArgs(), GenerateFileSystemArgs(), GenerateFrontendArgs(), GenerateHeaderSearchArgs(), GenerateMigratorArgs(), GeneratePreprocessorArgs(), GeneratePreprocessorOutputArgs(), GenerateTargetArgs(), clang::CompilerInvocationRefBase::HeaderSearchOpts, clang::CompilerInvocationRefBase::LangOpts, clang::CompilerInvocationValueBase::MigratorOpts, clang::FrontendOptions::OutputFile, clang::CompilerInvocationRefBase::PreprocessorOpts, clang::CompilerInvocationValueBase::PreprocessorOutputOpts, clang::FrontendOptions::ProgramAction, and clang::CompilerInvocationRefBase::TargetOpts.
Referenced by checkCC1RoundTrip(), CreateFromArgs(), getCC1CommandLine(), and getModuleContextHash().
std::vector< std::string > CompilerInvocation::getCC1CommandLine | ( | ) | const |
Generate cc1-compatible command line arguments from this instance, wrapping the result as a std::vector<std::string>.
This is a (less-efficient) wrapper over generateCC1CommandLine().
Definition at line 4620 of file CompilerInvocation.cpp.
References generateCC1CommandLine().
std::string CompilerInvocation::getModuleHash | ( | ) | const |
Retrieve a module hash string that is suitable for uniquely identifying the conditions under which the module was built.
Definition at line 4503 of file CompilerInvocation.cpp.
References clang::SanitizerSet::clear(), clang::PreprocessorOptions::DetailedRecord, clang::SanitizerSet::empty(), clang::getClangFullRepositoryVersion(), clang::CompilerInvocationValueBase::getCodeGenOpts(), clang::CompilerInvocationRefBase::getDiagnosticOpts(), clang::CompilerInvocationValueBase::getFrontendOpts(), clang::CompilerInvocationRefBase::getHeaderSearchOpts(), clang::getPPTransparentSanitizers(), clang::CompilerInvocationRefBase::getPreprocessorOpts(), clang::CompilerInvocationRefBase::LangOpts, clang::SanitizerSet::Mask, clang::HeaderSearchOptions::ModuleFormat, clang::HeaderSearchOptions::ModulesIgnoreMacros, clang::HeaderSearchOptions::ModulesStrictContextHash, clang::HeaderSearchOptions::ModulesValidateDiagnosticOptions, clang::HeaderSearchOptions::ModuleUserBuildPath, clang::HeaderSearchOptions::ResourceDir, clang::Result, clang::HeaderSearchOptions::Sysroot, clang::HeaderSearchOptions::SystemHeaderPrefixes, clang::CompilerInvocationRefBase::TargetOpts, toString(), clang::HeaderSearchOptions::UseBuiltinIncludes, clang::HeaderSearchOptions::UseDebugInfo, clang::HeaderSearchOptions::UseLibcxx, clang::PreprocessorOptions::UsePredefines, clang::HeaderSearchOptions::UserEntries, clang::HeaderSearchOptions::UseStandardCXXIncludes, clang::HeaderSearchOptions::UseStandardSystemIncludes, clang::serialization::VERSION_MAJOR, and clang::serialization::VERSION_MINOR.
Referenced by clang::CompilerInstance::createPreprocessor(), and clang::tooling::dependencies::ModuleDepCollectorPP::LexedFileChanged().
|
static |
Get the directory where the compiler headers reside, relative to the compiler binary (found by the passed in arguments).
Argv0 | - The program path (from argv[0]), for finding the builtin compiler path. |
MainAddr | - The address of main (or some other function in the main executable), for finding the builtin compiler path. |
Definition at line 2919 of file CompilerInvocation.cpp.
References clang::driver::Driver::GetResourcesPath().
Referenced by injectResourceDir().
void CompilerInvocation::resetNonModularOptions | ( | ) |
Reset all of the options that are not considered when building a module.
Definition at line 4634 of file CompilerInvocation.cpp.
References clang::CompilerInvocationRefBase::getLangOpts(), clang::CompilerInvocationRefBase::getPreprocessorOpts(), clang::LangOptions::resetNonModularOptions(), and clang::PreprocessorOptions::resetNonModularOptions().