clang  13.0.0git
List of all members
clang::CompilerInvocation Class Reference

Helper class for holding the data necessary to invoke the compiler. More...

#include "clang/Frontend/CompilerInvocation.h"

Inheritance diagram for clang::CompilerInvocation:
Inheritance graph
Collaboration diagram for clang::CompilerInvocation:
Collaboration graph

Public Member Functions

Option Subgroups
MigratorOptionsgetMigratorOpts ()
const MigratorOptionsgetMigratorOpts () const
CodeGenOptionsgetCodeGenOpts ()
const CodeGenOptionsgetCodeGenOpts () const
DependencyOutputOptionsgetDependencyOutputOpts ()
const DependencyOutputOptionsgetDependencyOutputOpts () const
FileSystemOptionsgetFileSystemOpts ()
const FileSystemOptionsgetFileSystemOpts () const
FrontendOptionsgetFrontendOpts ()
const FrontendOptionsgetFrontendOpts () const
PreprocessorOutputOptionsgetPreprocessorOutputOpts ()
const PreprocessorOutputOptionsgetPreprocessorOutputOpts () const
- Public Member Functions inherited from clang::CompilerInvocationBase
 CompilerInvocationBase ()
 CompilerInvocationBase (const CompilerInvocationBase &X)
CompilerInvocationBaseoperator= (const CompilerInvocationBase &)=delete
 ~CompilerInvocationBase ()
LangOptionsgetLangOpts ()
const LangOptionsgetLangOpts () const
TargetOptionsgetTargetOpts ()
const TargetOptionsgetTargetOpts () const
DiagnosticOptionsgetDiagnosticOpts () const
HeaderSearchOptionsgetHeaderSearchOpts ()
const HeaderSearchOptionsgetHeaderSearchOpts () const
std::shared_ptr< HeaderSearchOptionsgetHeaderSearchOptsPtr () const
std::shared_ptr< PreprocessorOptionsgetPreprocessorOptsPtr ()
PreprocessorOptionsgetPreprocessorOpts ()
const PreprocessorOptionsgetPreprocessorOpts () const
AnalyzerOptionsRef getAnalyzerOpts () const

Utility Methods

using StringAllocator = llvm::function_ref< const char *(const llvm::Twine &)>
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. More...
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). More...
static void setLangDefaults (LangOptions &Opts, InputKind IK, const llvm::Triple &T, std::vector< std::string > &Includes, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
 Set language defaults for the given input language and language standard in the given LangOptions object. More...
std::string getModuleHash () const
 Retrieve a module hash string that is suitable for uniquely identifying the conditions under which the module was built. More...
void generateCC1CommandLine (llvm::SmallVectorImpl< const char * > &Args, StringAllocator SA) const
 Generate a cc1-compatible command line arguments from this instance. More...

Additional Inherited Members

- Public Attributes inherited from clang::CompilerInvocationBase
std::shared_ptr< LangOptionsLangOpts
 Options controlling the language variant. More...
std::shared_ptr< TargetOptionsTargetOpts
 Options controlling the target. More...
IntrusiveRefCntPtr< DiagnosticOptionsDiagnosticOpts
 Options controlling the diagnostic engine. More...
std::shared_ptr< HeaderSearchOptionsHeaderSearchOpts
 Options controlling the #include directive. More...
std::shared_ptr< PreprocessorOptionsPreprocessorOpts
 Options controlling the preprocessor (aside from #include handling). More...
AnalyzerOptionsRef AnalyzerOpts
 Options controlling the static analyzer. More...

Detailed Description

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 125 of file CompilerInvocation.h.

Member Typedef Documentation

◆ StringAllocator

using clang::CompilerInvocation::StringAllocator = llvm::function_ref<const char *(const llvm::Twine &)>

Definition at line 190 of file CompilerInvocation.h.

Member Function Documentation

◆ CreateFromArgs()

bool CompilerInvocation::CreateFromArgs ( CompilerInvocation Res,
ArrayRef< const char * >  CommandLineArgs,
DiagnosticsEngine Diags,
const char *  Argv0 = nullptr 

Create a compiler invocation from a list of input options.

true on success.
false if an error was encountered while parsing the arguments and attempts to recover and continue parsing the rest of the arguments. The recovery is best-effort and only guarantees that 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 4396 of file CompilerInvocation.cpp.

References generateCC1CommandLine(), and RoundTrip().

Referenced by clang::createInvocationFromCommandLine(), main(), and clang::tooling::newInvocation().

◆ generateCC1CommandLine()

void CompilerInvocation::generateCC1CommandLine ( llvm::SmallVectorImpl< const char * > &  Args,
StringAllocator  SA 
) const

Generate a 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 4525 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::AnalyzerOpts, clang::FrontendOptions::DashX, clang::CompilerInvocationBase::DiagnosticOpts, GenerateAnalyzerArgs(), GenerateArg(), GenerateDependencyOutputArgs(), GenerateFileSystemArgs(), GenerateFrontendArgs(), GenerateHeaderSearchArgs(), GenerateMigratorArgs(), GeneratePreprocessorArgs(), GeneratePreprocessorOutputArgs(), GenerateTargetArgs(), clang::InputKind::getFormat(), clang::InputKind::getLanguage(), clang::CompilerInvocationBase::HeaderSearchOpts, clang::CompilerInvocationBase::LangOpts, clang::LLVM_IR, clang::FrontendOptions::OutputFile, clang::InputKind::Precompiled, clang::CompilerInvocationBase::PreprocessorOpts, clang::FrontendOptions::ProgramAction, serializeSanitizerKinds(), and clang::CompilerInvocationBase::TargetOpts.

Referenced by CreateFromArgs().

◆ getCodeGenOpts() [1/2]

CodeGenOptions& clang::CompilerInvocation::getCodeGenOpts ( )

◆ getCodeGenOpts() [2/2]

const CodeGenOptions& clang::CompilerInvocation::getCodeGenOpts ( ) const

Definition at line 210 of file CompilerInvocation.h.

◆ getDependencyOutputOpts() [1/2]

DependencyOutputOptions& clang::CompilerInvocation::getDependencyOutputOpts ( )

Definition at line 212 of file CompilerInvocation.h.

◆ getDependencyOutputOpts() [2/2]

const DependencyOutputOptions& clang::CompilerInvocation::getDependencyOutputOpts ( ) const

Definition at line 216 of file CompilerInvocation.h.

◆ getFileSystemOpts() [1/2]

FileSystemOptions& clang::CompilerInvocation::getFileSystemOpts ( )

Definition at line 220 of file CompilerInvocation.h.

Referenced by createInvocationForMigration().

◆ getFileSystemOpts() [2/2]

const FileSystemOptions& clang::CompilerInvocation::getFileSystemOpts ( ) const

Definition at line 222 of file CompilerInvocation.h.

◆ getFrontendOpts() [1/2]

FrontendOptions& clang::CompilerInvocation::getFrontendOpts ( )

◆ getFrontendOpts() [2/2]

const FrontendOptions& clang::CompilerInvocation::getFrontendOpts ( ) const

Definition at line 227 of file CompilerInvocation.h.

◆ getMigratorOpts() [1/2]

MigratorOptions& clang::CompilerInvocation::getMigratorOpts ( )

Definition at line 206 of file CompilerInvocation.h.

Referenced by applyTransforms(), and clang::arcmt::checkForManualIssues().

◆ getMigratorOpts() [2/2]

const MigratorOptions& clang::CompilerInvocation::getMigratorOpts ( ) const

Definition at line 207 of file CompilerInvocation.h.

◆ getModuleHash()

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 4412 of file CompilerInvocation.cpp.

References clang::SanitizerSet::clear(), clang::PreprocessorOptions::DetailedRecord, clang::SanitizerSet::empty(), clang::getClangFullRepositoryVersion(), getCodeGenOpts(), clang::CompilerInvocationBase::getDiagnosticOpts(), getFrontendOpts(), clang::CompilerInvocationBase::getHeaderSearchOpts(), clang::getPPTransparentSanitizers(), clang::CompilerInvocationBase::getPreprocessorOpts(), clang::format::hash_combine(), clang::hash_value(), clang::CompilerInvocationBase::LangOpts, clang::SanitizerSet::Mask, clang::FrontendOptions::ModuleFileExtensions, clang::HeaderSearchOptions::ModuleFormat, clang::HeaderSearchOptions::ModulesIgnoreMacros, clang::HeaderSearchOptions::ModulesStrictContextHash, clang::HeaderSearchOptions::ModulesValidateDiagnosticOptions, clang::HeaderSearchOptions::ModuleUserBuildPath, clang::HeaderSearchOptions::ResourceDir, clang::HeaderSearchOptions::Sysroot, clang::HeaderSearchOptions::SystemHeaderPrefixes, clang::CompilerInvocationBase::TargetOpts, 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::FileChanged().

◆ getPreprocessorOutputOpts() [1/2]

PreprocessorOutputOptions& clang::CompilerInvocation::getPreprocessorOutputOpts ( )

Definition at line 229 of file CompilerInvocation.h.

◆ getPreprocessorOutputOpts() [2/2]

const PreprocessorOutputOptions& clang::CompilerInvocation::getPreprocessorOutputOpts ( ) const

Definition at line 233 of file CompilerInvocation.h.

◆ GetResourcesPath()

std::string CompilerInvocation::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).

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 2791 of file CompilerInvocation.cpp.

References string().

Referenced by injectResourceDir().

◆ setLangDefaults()

void CompilerInvocation::setLangDefaults ( LangOptions Opts,
InputKind  IK,
const llvm::Triple &  T,
std::vector< std::string > &  Includes,
LangStandard::Kind  LangStd = LangStandard::lang_unspecified 

Set language defaults for the given input language and language standard in the given LangOptions object.

Opts- The LangOptions object to set up.
IK- The input language.
T- The target triple.
Includes- The affected list of included files.
LangStd- The input language standard.

Definition at line 3059 of file CompilerInvocation.cpp.

References clang::Asm, clang::C, clang::CUDA, clang::CXX, clang::LangOptions::FPM_Fast, clang::LangOptions::FPM_FastHonorPragmas, clang::LangOptions::FPM_On, clang::LangStandard::getLangStandardForKind(), clang::InputKind::getLanguage(), clang::HIP, clang::InputKind::isObjectiveC(), clang::LangStandard::lang_unspecified, clang::LangOptions::LangStd, clang::LLVM_IR, clang::ObjC, clang::ObjCXX, clang::OpenCL, clang::OpenCLCXX, clang::RenderScript, Std, and clang::Unknown.

The documentation for this class was generated from the following files: