clang 20.0.0git
Public Member Functions | Static Public Member Functions | 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
[legend]

Public Member Functions

 CompilerInvocation ()=default
 
 CompilerInvocation (const CompilerInvocation &X)
 
 CompilerInvocation (CompilerInvocation &&)=default
 
CompilerInvocationoperator= (const CompilerInvocation &X)
 
 ~CompilerInvocation ()=default
 
 CompilerInvocation (const CowCompilerInvocation &X)
 
CompilerInvocationoperator= (const CowCompilerInvocation &X)
 
std::string getModuleHash () const
 Retrieve a module hash string that is suitable for uniquely identifying the conditions under which the module was built.
 
void resetNonModularOptions ()
 Reset all of the options that are not considered when building a module.
 
void clearImplicitModuleBuildOptions ()
 Disable implicit modules and canonicalize options that are only used by implicit modules.
 
LangOptionsgetLangOpts ()
 Mutable getters.
 
TargetOptionsgetTargetOpts ()
 
DiagnosticOptionsgetDiagnosticOpts ()
 
HeaderSearchOptionsgetHeaderSearchOpts ()
 
PreprocessorOptionsgetPreprocessorOpts ()
 
AnalyzerOptionsgetAnalyzerOpts ()
 
MigratorOptionsgetMigratorOpts ()
 
APINotesOptionsgetAPINotesOpts ()
 
CodeGenOptionsgetCodeGenOpts ()
 
FileSystemOptionsgetFileSystemOpts ()
 
FrontendOptionsgetFrontendOpts ()
 
DependencyOutputOptionsgetDependencyOutputOpts ()
 
PreprocessorOutputOptionsgetPreprocessorOutputOpts ()
 
const LangOptionsgetLangOpts () const
 Const getters.
 
const TargetOptionsgetTargetOpts () const
 
const DiagnosticOptionsgetDiagnosticOpts () const
 
const HeaderSearchOptionsgetHeaderSearchOpts () const
 
const PreprocessorOptionsgetPreprocessorOpts () const
 
const AnalyzerOptionsgetAnalyzerOpts () const
 
const MigratorOptionsgetMigratorOpts () const
 
const APINotesOptionsgetAPINotesOpts () const
 
const CodeGenOptionsgetCodeGenOpts () const
 
const FileSystemOptionsgetFileSystemOpts () const
 
const FrontendOptionsgetFrontendOpts () const
 
const DependencyOutputOptionsgetDependencyOutputOpts () const
 
const PreprocessorOutputOptionsgetPreprocessorOutputOpts () const
 
- Public Member Functions inherited from clang::CompilerInvocationBase
const LangOptionsgetLangOpts () const
 Const getters.
 
const TargetOptionsgetTargetOpts () const
 
const DiagnosticOptionsgetDiagnosticOpts () const
 
const HeaderSearchOptionsgetHeaderSearchOpts () const
 
const PreprocessorOptionsgetPreprocessorOpts () const
 
const AnalyzerOptionsgetAnalyzerOpts () const
 
const MigratorOptionsgetMigratorOpts () const
 
const APINotesOptionsgetAPINotesOpts () const
 
const CodeGenOptionsgetCodeGenOpts () const
 
const FileSystemOptionsgetFileSystemOpts () const
 
const FrontendOptionsgetFrontendOpts () const
 
const DependencyOutputOptionsgetDependencyOutputOpts () const
 
const PreprocessorOutputOptionsgetPreprocessorOutputOpts () const
 
void generateCC1CommandLine (llvm::SmallVectorImpl< const char * > &Args, StringAllocator SA) const
 Generate cc1-compatible command line arguments from this instance.
 
void generateCC1CommandLine (ArgumentConsumer Consumer) const
 Generate cc1-compatible command line arguments from this instance.
 
std::vector< std::string > getCC1CommandLine () const
 Generate cc1-compatible command line arguments from this instance, wrapping the result as a std::vector<std::string>.
 

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 void setDefaultPointerAuthOptions (PointerAuthOptions &Opts, const LangOptions &LangOpts, const llvm::Triple &Triple)
 Populate Opts with the default set of pointer authentication-related options given LangOpts and Triple.
 
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.
 
std::shared_ptr< HeaderSearchOptionsgetHeaderSearchOptsPtr ()
 
std::shared_ptr< PreprocessorOptionsgetPreprocessorOptsPtr ()
 
std::shared_ptr< LangOptionsgetLangOptsPtr ()
 
std::shared_ptr< LangOptionsLangOpts
 Base class internals.
 
std::shared_ptr< TargetOptionsTargetOpts
 Options controlling the target.
 
IntrusiveRefCntPtr< DiagnosticOptionsDiagnosticOpts
 Options controlling the diagnostic engine.
 

Additional Inherited Members

- Public Types inherited from clang::CompilerInvocationBase
using StringAllocator = llvm::function_ref< const char *(const Twine &)>
 Command line generation.
 
using ArgumentConsumer = llvm::function_ref< void(const Twine &)>
 
- Protected Member Functions inherited from clang::CompilerInvocationBase
 CompilerInvocationBase ()
 
 CompilerInvocationBase (EmptyConstructor)
 
 CompilerInvocationBase (const CompilerInvocationBase &X)=delete
 
 CompilerInvocationBase (CompilerInvocationBase &&X)=default
 
CompilerInvocationBaseoperator= (const CompilerInvocationBase &X)=delete
 
CompilerInvocationBasedeep_copy_assign (const CompilerInvocationBase &X)
 
CompilerInvocationBaseshallow_copy_assign (const CompilerInvocationBase &X)
 
CompilerInvocationBaseoperator= (CompilerInvocationBase &&X)=default
 
 ~CompilerInvocationBase ()=default
 
- Protected Attributes inherited from clang::CompilerInvocationBase
std::shared_ptr< LangOptionsLangOpts
 Options controlling the language variant.
 
std::shared_ptr< TargetOptionsTargetOpts
 Options controlling the target.
 
IntrusiveRefCntPtr< DiagnosticOptionsDiagnosticOpts
 Options controlling the diagnostic engine.
 
std::shared_ptr< HeaderSearchOptionsHSOpts
 Options controlling the #include directive.
 
std::shared_ptr< PreprocessorOptionsPPOpts
 Options controlling the preprocessor (aside from #include handling).
 
AnalyzerOptionsRef AnalyzerOpts
 Options controlling the static analyzer.
 
std::shared_ptr< MigratorOptionsMigratorOpts
 
std::shared_ptr< APINotesOptionsAPINotesOpts
 Options controlling API notes.
 
std::shared_ptr< CodeGenOptionsCodeGenOpts
 Options controlling IRgen and the backend.
 
std::shared_ptr< FileSystemOptionsFSOpts
 Options controlling file system operations.
 
std::shared_ptr< FrontendOptionsFrontendOpts
 Options controlling the frontend itself.
 
std::shared_ptr< DependencyOutputOptionsDependencyOutputOpts
 Options controlling dependency output.
 
std::shared_ptr< PreprocessorOutputOptionsPreprocessorOutputOpts
 Options controlling preprocessed output.
 

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

Constructor & Destructor Documentation

◆ CompilerInvocation() [1/4]

clang::CompilerInvocation::CompilerInvocation ( )
default

◆ CompilerInvocation() [2/4]

clang::CompilerInvocation::CompilerInvocation ( const CompilerInvocation X)
inline

Definition at line 214 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::deep_copy_assign(), and X.

◆ CompilerInvocation() [3/4]

clang::CompilerInvocation::CompilerInvocation ( CompilerInvocation &&  )
default

◆ ~CompilerInvocation()

clang::CompilerInvocation::~CompilerInvocation ( )
default

◆ CompilerInvocation() [4/4]

CompilerInvocation::CompilerInvocation ( const CowCompilerInvocation X)
explicit

Definition at line 194 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::deep_copy_assign(), and X.

Member Function Documentation

◆ checkCC1RoundTrip()

bool CompilerInvocation::checkCC1RoundTrip ( ArrayRef< const char * >  Args,
DiagnosticsEngine Diags,
const char *  Argv0 = nullptr 
)
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.

Returns
false if there are any errors.

Definition at line 915 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::generateCC1CommandLine(), and RoundTrip().

◆ clearImplicitModuleBuildOptions()

void CompilerInvocation::clearImplicitModuleBuildOptions ( )

◆ CreateFromArgs()

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

Create a compiler invocation from a list of input options.

Returns
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.
Parameters
[out]Res- The resulting invocation.
[in]CommandLineArgs- Array of argument strings, this must not contain "-cc1".

Definition at line 4925 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::generateCC1CommandLine(), and RoundTrip().

Referenced by clang::createInvocation(), clang::tooling::newInvocation(), and clang::TestAST::TestAST().

◆ getAnalyzerOpts() [1/2]

AnalyzerOptions & clang::CompilerInvocation::getAnalyzerOpts ( )
inline

Definition at line 254 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::AnalyzerOpts.

◆ getAnalyzerOpts() [2/2]

const AnalyzerOptions & clang::CompilerInvocationBase::getAnalyzerOpts ( ) const
inline

Definition at line 136 of file CompilerInvocation.h.

◆ getAPINotesOpts() [1/2]

APINotesOptions & clang::CompilerInvocation::getAPINotesOpts ( )
inline

Definition at line 256 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::APINotesOpts.

Referenced by getModuleHash().

◆ getAPINotesOpts() [2/2]

const APINotesOptions & clang::CompilerInvocationBase::getAPINotesOpts ( ) const
inline

Definition at line 138 of file CompilerInvocation.h.

◆ getCodeGenOpts() [1/2]

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

◆ getCodeGenOpts() [2/2]

const CodeGenOptions & clang::CompilerInvocationBase::getCodeGenOpts ( ) const
inline

Definition at line 139 of file CompilerInvocation.h.

◆ getDependencyOutputOpts() [1/2]

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

◆ getDependencyOutputOpts() [2/2]

const DependencyOutputOptions & clang::CompilerInvocationBase::getDependencyOutputOpts ( ) const
inline

Definition at line 142 of file CompilerInvocation.h.

◆ getDiagnosticOpts() [1/2]

DiagnosticOptions & clang::CompilerInvocation::getDiagnosticOpts ( )
inline

◆ getDiagnosticOpts() [2/2]

const DiagnosticOptions & clang::CompilerInvocationBase::getDiagnosticOpts ( ) const
inline

Definition at line 133 of file CompilerInvocation.h.

◆ getFileSystemOpts() [1/2]

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

Definition at line 258 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::FSOpts.

Referenced by createInvocationForMigration().

◆ getFileSystemOpts() [2/2]

const FileSystemOptions & clang::CompilerInvocationBase::getFileSystemOpts ( ) const
inline

Definition at line 140 of file CompilerInvocation.h.

◆ getFrontendOpts() [1/2]

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

◆ getFrontendOpts() [2/2]

const FrontendOptions & clang::CompilerInvocationBase::getFrontendOpts ( ) const
inline

Definition at line 141 of file CompilerInvocation.h.

◆ getHeaderSearchOpts() [1/2]

HeaderSearchOptions & clang::CompilerInvocation::getHeaderSearchOpts ( )
inline

◆ getHeaderSearchOpts() [2/2]

const HeaderSearchOptions & clang::CompilerInvocationBase::getHeaderSearchOpts ( ) const
inline

Definition at line 134 of file CompilerInvocation.h.

◆ getHeaderSearchOptsPtr()

std::shared_ptr< HeaderSearchOptions > clang::CompilerInvocation::getHeaderSearchOptsPtr ( )
inline

Definition at line 273 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::HSOpts.

◆ getLangOpts() [1/2]

LangOptions & clang::CompilerInvocation::getLangOpts ( )
inline

◆ getLangOpts() [2/2]

const LangOptions & clang::CompilerInvocationBase::getLangOpts ( ) const
inline

Const getters.

Definition at line 131 of file CompilerInvocation.h.

◆ getLangOptsPtr()

std::shared_ptr< LangOptions > clang::CompilerInvocation::getLangOptsPtr ( )
inline

Definition at line 279 of file CompilerInvocation.h.

References LangOpts.

◆ getMigratorOpts() [1/2]

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

◆ getMigratorOpts() [2/2]

const MigratorOptions & clang::CompilerInvocationBase::getMigratorOpts ( ) const
inline

Definition at line 137 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 4944 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::APINotesOpts, clang::SanitizerSet::clear(), clang::PreprocessorOptions::DetailedRecord, clang::SanitizerSet::empty(), getAPINotesOpts(), clang::getClangFullRepositoryVersion(), getCodeGenOpts(), getDiagnosticOpts(), getFrontendOpts(), getHeaderSearchOpts(), getLangOpts(), clang::getPPTransparentSanitizers(), getPreprocessorOpts(), getTargetOpts(), clang::SanitizerSet::Mask, clang::HeaderSearchOptions::ModuleFormat, clang::HeaderSearchOptions::ModulesIgnoreMacros, clang::HeaderSearchOptions::ModulesStrictContextHash, clang::HeaderSearchOptions::ModulesValidateDiagnosticOptions, clang::HeaderSearchOptions::ModuleUserBuildPath, clang::HeaderSearchOptions::ResourceDir, clang::Result, clang::LangOptions::Sanitize, clang::HeaderSearchOptions::Sysroot, clang::HeaderSearchOptions::SystemHeaderPrefixes, 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, clang::serialization::VERSION_MINOR, and clang::HeaderSearchOptions::VFSOverlayFiles.

Referenced by clang::CompilerInstance::createPreprocessor(), and clang::tooling::dependencies::ModuleDepCollectorPP::LexedFileChanged().

◆ getPreprocessorOpts() [1/2]

PreprocessorOptions & clang::CompilerInvocation::getPreprocessorOpts ( )
inline

◆ getPreprocessorOpts() [2/2]

const PreprocessorOptions & clang::CompilerInvocationBase::getPreprocessorOpts ( ) const
inline

Definition at line 135 of file CompilerInvocation.h.

◆ getPreprocessorOptsPtr()

std::shared_ptr< PreprocessorOptions > clang::CompilerInvocation::getPreprocessorOptsPtr ( )
inline

Definition at line 276 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::PPOpts.

◆ getPreprocessorOutputOpts() [1/2]

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

◆ getPreprocessorOutputOpts() [2/2]

const PreprocessorOutputOptions & clang::CompilerInvocationBase::getPreprocessorOutputOpts ( ) const
inline

Definition at line 145 of file CompilerInvocation.h.

◆ GetResourcesPath()

std::string CompilerInvocation::GetResourcesPath ( const char *  Argv0,
void *  MainAddr 
)
static

Get the directory where the compiler headers reside, relative to the compiler binary (found by the passed in arguments).

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

References clang::driver::Driver::GetResourcesPath().

Referenced by injectResourceDir().

◆ getTargetOpts() [1/2]

TargetOptions & clang::CompilerInvocation::getTargetOpts ( )
inline

Definition at line 250 of file CompilerInvocation.h.

References TargetOpts.

Referenced by FixupInvocation(), getModuleHash(), and HasARCRuntime().

◆ getTargetOpts() [2/2]

const TargetOptions & clang::CompilerInvocationBase::getTargetOpts ( ) const
inline

Definition at line 132 of file CompilerInvocation.h.

◆ operator=() [1/2]

CompilerInvocation & clang::CompilerInvocation::operator= ( const CompilerInvocation X)
inline

Definition at line 219 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::deep_copy_assign(), and X.

◆ operator=() [2/2]

CompilerInvocation & CompilerInvocation::operator= ( const CowCompilerInvocation X)

Definition at line 200 of file CompilerInvocation.cpp.

References clang::CompilerInvocationBase::deep_copy_assign(), and X.

◆ resetNonModularOptions()

void CompilerInvocation::resetNonModularOptions ( )

◆ setDefaultPointerAuthOptions()

void CompilerInvocation::setDefaultPointerAuthOptions ( PointerAuthOptions Opts,
const LangOptions LangOpts,
const llvm::Triple &  Triple 
)
static

Member Data Documentation

◆ DiagnosticOpts

IntrusiveRefCntPtr<DiagnosticOptions> clang::CompilerInvocationBase::DiagnosticOpts

Options controlling the diagnostic engine.

Definition at line 83 of file CompilerInvocation.h.

Referenced by getDiagnosticOpts().

◆ LangOpts

std::shared_ptr<LangOptions> clang::CompilerInvocationBase::LangOpts

Base class internals.

Definition at line 77 of file CompilerInvocation.h.

Referenced by getLangOpts(), getLangOptsPtr(), and setDefaultPointerAuthOptions().

◆ TargetOpts

std::shared_ptr<TargetOptions> clang::CompilerInvocationBase::TargetOpts

Options controlling the target.

Definition at line 80 of file CompilerInvocation.h.

Referenced by getTargetOpts().


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