clang 24.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
CompilerInvocation & operator= (const CompilerInvocation &X)
 ~CompilerInvocation ()=default
 CompilerInvocation (const CowCompilerInvocation &X)
CompilerInvocation & operator= (const CowCompilerInvocation &X)
template<class R>
R withCowRef (llvm::function_ref< R(CowCompilerInvocation &)> Fn)
 Invokes the Fn with CowCompilerInvocation representing this.
template<class R>
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.
CompilerInvocation & operator= (CowCompilerInvocation &&X)
LangOptions & getLangOpts ()
 Mutable getters.
TargetOptions & getTargetOpts ()
DiagnosticOptions & getDiagnosticOpts ()
HeaderSearchOptions & getHeaderSearchOpts ()
PreprocessorOptions & getPreprocessorOpts ()
AnalyzerOptions & getAnalyzerOpts ()
MigratorOptions & getMigratorOpts ()
APINotesOptions & getAPINotesOpts ()
CodeGenOptions & getCodeGenOpts ()
FileSystemOptions & getFileSystemOpts ()
FrontendOptions & getFrontendOpts ()
DependencyOutputOptions & getDependencyOutputOpts ()
PreprocessorOutputOptions & getPreprocessorOutputOpts ()
ssaf::SSAFOptions & getSSAFOpts ()
const AnalyzerOptions & getAnalyzerOpts () const
 Const getters.
const APINotesOptions & getAPINotesOpts () const
const CodeGenOptions & getCodeGenOpts () const
const DependencyOutputOptions & getDependencyOutputOpts () const
const DiagnosticOptions & getDiagnosticOpts () const
const FileSystemOptions & getFileSystemOpts () const
const FrontendOptions & getFrontendOpts () const
const HeaderSearchOptions & getHeaderSearchOpts () const
const LangOptions & getLangOpts () const
 Const getters.
const MigratorOptions & getMigratorOpts () const
const PreprocessorOptions & getPreprocessorOpts () const
const PreprocessorOutputOptions & getPreprocessorOutputOpts () const
const ssaf::SSAFOptions & getSSAFOpts () const
const TargetOptions & getTargetOpts () const
Public Member Functions inherited from clang::CompilerInvocationBase
const LangOptions & getLangOpts () const
 Const getters.
const TargetOptions & getTargetOpts () const
const DiagnosticOptions & getDiagnosticOpts () const
const HeaderSearchOptions & getHeaderSearchOpts () const
const PreprocessorOptions & getPreprocessorOpts () const
const AnalyzerOptions & getAnalyzerOpts () const
const MigratorOptions & getMigratorOpts () const
const APINotesOptions & getAPINotesOpts () const
const CodeGenOptions & getCodeGenOpts () const
const FileSystemOptions & getFileSystemOpts () const
const FrontendOptions & getFrontendOpts () const
const DependencyOutputOptions & getDependencyOutputOpts () const
const PreprocessorOutputOptions & getPreprocessorOutputOpts () const
const ssaf::SSAFOptions & getSSAFOpts () 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
CompilerInvocationBase & operator= (const CompilerInvocationBase &X)=delete
CompilerInvocationBase & deep_copy_assign (const CompilerInvocationBase &X)
CompilerInvocationBase & shallow_copy_assign (const CompilerInvocationBase &X)
CompilerInvocationBase & operator= (CompilerInvocationBase &&X)=default
 ~CompilerInvocationBase ()=default
Protected Attributes inherited from clang::CompilerInvocationBase
std::shared_ptr< LangOptions > LangOpts
 Options controlling the language variant.
std::shared_ptr< TargetOptions > TargetOpts
 Options controlling the target.
std::shared_ptr< DiagnosticOptions > DiagnosticOpts
 Options controlling the diagnostic engine.
std::shared_ptr< HeaderSearchOptions > HSOpts
 Options controlling the #include directive.
std::shared_ptr< PreprocessorOptions > PPOpts
 Options controlling the preprocessor (aside from #include handling).
std::shared_ptr< AnalyzerOptions > AnalyzerOpts
 Options controlling the static analyzer.
std::shared_ptr< MigratorOptions > MigratorOpts
std::shared_ptr< APINotesOptions > APINotesOpts
 Options controlling API notes.
std::shared_ptr< CodeGenOptions > CodeGenOpts
 Options controlling IRgen and the backend.
std::shared_ptr< FileSystemOptions > FSOpts
 Options controlling file system operations.
std::shared_ptr< FrontendOptions > FrontendOpts
 Options controlling the frontend itself.
std::shared_ptr< DependencyOutputOptions > DependencyOutputOpts
 Options controlling dependency output.
std::shared_ptr< PreprocessorOutputOptions > PreprocessorOutputOpts
 Options controlling preprocessed output.
std::shared_ptr< ssaf::SSAFOptions > SSAFOpts
 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 224 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 469 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 879 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 5266 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::SanitizerSet::Mask, clang::HeaderSearchOptions::ModuleFormat, clang::HeaderSearchOptions::ModulesIgnoreMacros, clang::HeaderSearchOptions::ModulesIgnoreSearchPaths, 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 5247 of file CompilerInvocation.cpp.

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

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

◆ getAnalyzerOpts() [1/2]

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

Definition at line 277 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::AnalyzerOpts.

◆ getAnalyzerOpts() [2/2]

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

Const getters.

Definition at line 148 of file CompilerInvocation.h.

◆ getAPINotesOpts() [1/2]

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

Definition at line 279 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::APINotesOpts.

Referenced by computeContextHash().

◆ getAPINotesOpts() [2/2]

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

Definition at line 150 of file CompilerInvocation.h.

◆ getCodeGenOpts() [1/2]

◆ getCodeGenOpts() [2/2]

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

Definition at line 151 of file CompilerInvocation.h.

◆ getDependencyOutputOpts() [1/2]

◆ getDependencyOutputOpts() [2/2]

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

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

◆ getFileSystemOpts() [1/2]

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

Definition at line 281 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::FSOpts.

◆ getFileSystemOpts() [2/2]

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

Definition at line 152 of file CompilerInvocation.h.

◆ getFrontendOpts() [1/2]

◆ getFrontendOpts() [2/2]

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

Definition at line 153 of file CompilerInvocation.h.

◆ getHeaderSearchOpts() [1/2]

◆ getHeaderSearchOpts() [2/2]

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

Definition at line 146 of file CompilerInvocation.h.

◆ getLangOpts() [1/2]

◆ getLangOpts() [2/2]

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

Const getters.

Definition at line 143 of file CompilerInvocation.h.

◆ getMigratorOpts() [1/2]

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

Definition at line 278 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::MigratorOpts.

◆ getMigratorOpts() [2/2]

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

Definition at line 149 of file CompilerInvocation.h.

◆ getPreprocessorOpts() [1/2]

◆ getPreprocessorOpts() [2/2]

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

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

◆ getSSAFOpts() [1/2]

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

Definition at line 289 of file CompilerInvocation.h.

References clang::CompilerInvocationBase::SSAFOpts.

◆ getSSAFOpts() [2/2]

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

Definition at line 160 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 144 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 473 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 1453 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::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 460 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 449 of file CompilerInvocation.h.

Referenced by clang::dependencies::CompilerInstanceWithContext::applyAndReport(), and clang::dependencies::CompilerInstanceWithContext::computeDependencies().


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