clang 23.0.0git
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:
[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)
template<class R>
withCowRef (llvm::function_ref< R(CowCompilerInvocation &)> Fn)
 Invokes the Fn with CowCompilerInvocation representing this.
template<class R>
withCowRef (llvm::function_ref< R(const CowCompilerInvocation &)> Fn) const
std::string computeContextHash () const
 Compute the context hash - a string that uniquely identifies compiler settings.
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.
 CompilerInvocation (CowCompilerInvocation &&X)
 Move-construct/move-assign from a CowCompilerInvocation.
CompilerInvocationoperator= (CowCompilerInvocation &&X)
LangOptionsgetLangOpts ()
 Mutable getters.
TargetOptionsgetTargetOpts ()
DiagnosticOptionsgetDiagnosticOpts ()
HeaderSearchOptionsgetHeaderSearchOpts ()
PreprocessorOptionsgetPreprocessorOpts ()
AnalyzerOptionsgetAnalyzerOpts ()
MigratorOptionsgetMigratorOpts ()
APINotesOptionsgetAPINotesOpts ()
CodeGenOptionsgetCodeGenOpts ()
FileSystemOptionsgetFileSystemOpts ()
FrontendOptionsgetFrontendOpts ()
DependencyOutputOptionsgetDependencyOutputOpts ()
PreprocessorOutputOptionsgetPreprocessorOutputOpts ()
ssaf::SSAFOptionsgetSSAFOpts ()
const AnalyzerOptionsgetAnalyzerOpts () const
 Const getters.
const APINotesOptionsgetAPINotesOpts () const
const CodeGenOptionsgetCodeGenOpts () const
const DependencyOutputOptionsgetDependencyOutputOpts () const
const DiagnosticOptionsgetDiagnosticOpts () const
const FileSystemOptionsgetFileSystemOpts () const
const FrontendOptionsgetFrontendOpts () const
const HeaderSearchOptionsgetHeaderSearchOpts () const
const LangOptionsgetLangOpts () const
 Const getters.
const MigratorOptionsgetMigratorOpts () const
const PreprocessorOptionsgetPreprocessorOpts () const
const PreprocessorOutputOptionsgetPreprocessorOutputOpts () const
const ssaf::SSAFOptionsgetSSAFOpts () const
const TargetOptionsgetTargetOpts () 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
const ssaf::SSAFOptionsgetSSAFOpts () 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 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.

Additional Inherited Members

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.
std::shared_ptr< 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).
std::shared_ptr< AnalyzerOptionsAnalyzerOpts
 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.
std::shared_ptr< ssaf::SSAFOptionsSSAFOpts
 Options controlling the Scalable Static Analysis Framework (SSAF).

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

Constructor & Destructor Documentation

◆ CompilerInvocation() [1/5]

clang::CompilerInvocation::CompilerInvocation ( )
default

◆ CompilerInvocation() [2/5]

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

◆ CompilerInvocation() [3/5]

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

References CompilerInvocation().

◆ ~CompilerInvocation()

◆ CompilerInvocation() [4/5]

CompilerInvocation::CompilerInvocation ( const CowCompilerInvocation & X)
explicit

◆ CompilerInvocation() [5/5]

clang::CompilerInvocation::CompilerInvocation ( CowCompilerInvocation && X)
inlineexplicit

Move-construct/move-assign from a CowCompilerInvocation.

Steals the (potentially copy-on-written) option group pointers without deep-copying; X is left empty. Useful to receive results of mutating a temporary Cow alias back into a CompilerInvocation.

Definition at line 474 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::CompilerInvocationBase(), 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 883 of file CompilerInvocation.cpp.

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

◆ clearImplicitModuleBuildOptions()

◆ computeContextHash()

std::string CompilerInvocation::computeContextHash ( ) const

Compute the context hash - a string that uniquely identifies compiler settings.

This is currently used mainly for distinguishing different variants of the same implicitly-built Clang module.

Definition at line 5225 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::Macro, clang::Macros, 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::FrontendAction::BeginSourceFile().

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

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

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

◆ getAnalyzerOpts() [1/2]

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

Definition at line 282 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::AnalyzerOpts.

◆ getAnalyzerOpts() [2/2]

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

Const getters.

Definition at line 153 of file CompilerInvocation.h.

◆ getAPINotesOpts() [1/2]

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

Definition at line 284 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::APINotesOpts.

Referenced by computeContextHash().

◆ getAPINotesOpts() [2/2]

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

Definition at line 155 of file CompilerInvocation.h.

◆ getCodeGenOpts() [1/2]

◆ getCodeGenOpts() [2/2]

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

Definition at line 156 of file CompilerInvocation.h.

◆ getDependencyOutputOpts() [1/2]

◆ getDependencyOutputOpts() [2/2]

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

Definition at line 159 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 150 of file CompilerInvocation.h.

◆ getFileSystemOpts() [1/2]

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

Definition at line 286 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::FSOpts.

◆ getFileSystemOpts() [2/2]

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

Definition at line 157 of file CompilerInvocation.h.

◆ getFrontendOpts() [1/2]

◆ getFrontendOpts() [2/2]

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

Definition at line 158 of file CompilerInvocation.h.

◆ getHeaderSearchOpts() [1/2]

◆ getHeaderSearchOpts() [2/2]

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

Definition at line 151 of file CompilerInvocation.h.

◆ getLangOpts() [1/2]

◆ getLangOpts() [2/2]

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

Const getters.

Definition at line 148 of file CompilerInvocation.h.

◆ getMigratorOpts() [1/2]

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

Definition at line 283 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::MigratorOpts.

◆ getMigratorOpts() [2/2]

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

Definition at line 154 of file CompilerInvocation.h.

◆ getPreprocessorOpts() [1/2]

◆ getPreprocessorOpts() [2/2]

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

Definition at line 152 of file CompilerInvocation.h.

◆ getPreprocessorOutputOpts() [1/2]

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

◆ getPreprocessorOutputOpts() [2/2]

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

Definition at line 162 of file CompilerInvocation.h.

◆ getSSAFOpts() [1/2]

ssaf::SSAFOptions & clang::CompilerInvocation::getSSAFOpts ( )
inline

Definition at line 294 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::SSAFOpts.

◆ getSSAFOpts() [2/2]

const ssaf::SSAFOptions & clang::CompilerInvocationBase::getSSAFOpts ( ) const
inline

Definition at line 165 of file CompilerInvocation.h.

◆ getTargetOpts() [1/2]

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

◆ getTargetOpts() [2/2]

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

Definition at line 149 of file CompilerInvocation.h.

◆ operator=() [1/3]

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

◆ operator=() [2/3]

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

Definition at line 188 of file CompilerInvocation.cpp.

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

◆ operator=() [3/3]

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

Definition at line 478 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::operator=(), and X.

◆ resetNonModularOptions()

void CompilerInvocation::resetNonModularOptions ( )

◆ setDefaultPointerAuthOptions()

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

Populate Opts with the default set of pointer authentication-related options given LangOpts and Triple.

Note: This is intended to be used by tools which must be aware of pointer authentication-related code generation, e.g. lldb.

Definition at line 1457 of file CompilerInvocation.cpp.

References clang::PointerAuthOptions::AArch64JumpTableHardening, clang::PointerAuthOptions::AuthTraps, clang::PointerAuthOptions::BlockByrefHelperFunctionPointers, clang::BlockDescriptorConstantDiscriminator, clang::PointerAuthOptions::BlockDescriptorPointers, clang::PointerAuthOptions::BlockHelperFunctionPointers, clang::PointerAuthOptions::BlockInvocationFunctionPointers, clang::ClassROConstantDiscriminator, clang::PointerAuthOptions::CXXMemberFunctionPointers, clang::PointerAuthOptions::CXXTypeInfoVTablePointer, clang::PointerAuthOptions::CXXVirtualFunctionPointers, clang::PointerAuthOptions::CXXVirtualVariadicFunctionPointers, clang::PointerAuthOptions::CXXVTablePointers, clang::PointerAuthOptions::CXXVTTVTablePointers, clang::PointerAuthOptions::FunctionPointers, clang::PointerAuthOptions::IndirectGotos, clang::InitFiniPointerConstantDiscriminator, clang::PointerAuthOptions::InitFiniPointers, clang::IsaPointerConstantDiscriminator, clang::CompilerInvocationBase::LangOpts, clang::MethodListPointerConstantDiscriminator, clang::PointerAuthOptions::ObjCClassROPointers, clang::PointerAuthOptions::ObjCIsaPointers, clang::PointerAuthOptions::ObjCMethodListFunctionPointers, clang::PointerAuthOptions::ObjCMethodListPointer, clang::PointerAuthOptions::ObjCSuperPointers, clang::PointerAuthOptions::ReturnAddresses, clang::StdTypeInfoVTablePointerConstantDiscrimination, and clang::SuperPointerConstantDiscriminator.

Referenced by parsePointerAuthOptions().

◆ withCowRef() [1/2]

template<class R>
R clang::CompilerInvocation::withCowRef ( llvm::function_ref< R(const CowCompilerInvocation &)> Fn) const

Definition at line 465 of file CompilerInvocation.h.

◆ withCowRef() [2/2]

template<class R>
R clang::CompilerInvocation::withCowRef ( llvm::function_ref< R(CowCompilerInvocation &)> Fn)

Invokes the Fn with CowCompilerInvocation representing this.

The Fn must not directly modify this. The provided CowCompilerInvocation must not escape Fn.

Definition at line 454 of file CompilerInvocation.h.

Referenced by clang::tooling::CompilerInstanceWithContext::computeDependencies().


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