clang API Documentation

Namespaces | Defines | Functions
CompilerInvocation.cpp File Reference
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/Version.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Util.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/LangStandard.h"
#include "clang/Frontend/Utils.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Serialization/ASTReader.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include <atomic>
#include <memory>
#include <sys/stat.h>
#include <system_error>
#include "clang/StaticAnalyzer/Core/Analyses.def"
#include "clang/Frontend/LangStandards.def"
#include "clang/Basic/Sanitizers.def"
#include "clang/Basic/LangOptions.def"
Include dependency graph for CompilerInvocation.cpp:

Go to the source code of this file.

Namespaces

namespace  clang

Defines

#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)   .Case(CMDFLAG, NAME##Model)
#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)   .Case(CMDFLAG, NAME##Model)
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)   .Case(CMDFLAG, PD_##NAME)
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC)   .Case(CMDFLAG, NAME)
#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC)   .Case(CMDFLAG, NAME)
#define LANGSTANDARD(id, name, desc, features)   .Case(name, LangStandard::lang_##id)
#define SANITIZER(NAME, ID)   .Case(NAME, SanitizerKind::ID)
#define LANGOPT(Name, Bits, Default, Description)   code = hash_combine(code, LangOpts->Name);
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)   code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name()));
#define BENIGN_LANGOPT(Name, Bits, Default, Description)
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)

Functions

static unsigned getOptimizationLevel (ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
static unsigned getOptimizationLevelSize (ArgList &Args)
static void addDiagnosticArgs (ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector< std::string > &Diagnostics)
static bool ParseAnalyzerArgs (AnalyzerOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
static bool ParseMigratorArgs (MigratorOptions &Opts, ArgList &Args)
static void ParseCommentArgs (CommentOptions &Opts, ArgList &Args)
static StringRef getCodeModel (ArgList &Args, DiagnosticsEngine &Diags)
static std::shared_ptr
< llvm::Regex > 
GenerateOptimizationRemarkRegex (DiagnosticsEngine &Diags, ArgList &Args, Arg *RpassArg)
 Create a new Regex instance out of the string value in RpassArg. It returns a pointer to the newly generated Regex instance.
static bool ParseCodeGenArgs (CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const TargetOptions &TargetOpts)
static void ParseDependencyOutputArgs (DependencyOutputOptions &Opts, ArgList &Args)
static void ParseFileSystemArgs (FileSystemOptions &Opts, ArgList &Args)
static InputKind ParseFrontendArgs (FrontendOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
static void ParseHeaderSearchArgs (HeaderSearchOptions &Opts, ArgList &Args)
static Visibility parseVisibility (Arg *arg, ArgList &args, DiagnosticsEngine &diags)
 Attempt to parse a visibility value out of the given argument.
static unsigned parseMSCVersion (ArgList &Args, DiagnosticsEngine &Diags)
static void ParseLangArgs (LangOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
static void ParsePreprocessorArgs (PreprocessorOptions &Opts, ArgList &Args, FileManager &FileMgr, DiagnosticsEngine &Diags)
static void ParsePreprocessorOutputArgs (PreprocessorOutputOptions &Opts, ArgList &Args, frontend::ActionKind Action)
static void ParseTargetArgs (TargetOptions &Opts, ArgList &Args)
template<typename IntTy >
static IntTy clang::getLastArgIntValueImpl (const ArgList &Args, OptSpecifier Id, IntTy Default, DiagnosticsEngine *Diags)
int clang::getLastArgIntValue (const ArgList &Args, OptSpecifier Id, int Default, DiagnosticsEngine *Diags)
uint64_t clang::getLastArgUInt64Value (const ArgList &Args, OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags)
void clang::BuryPointer (const void *Ptr)
IntrusiveRefCntPtr
< vfs::FileSystem
clang::createVFSFromCompilerInvocation (const CompilerInvocation &CI, DiagnosticsEngine &Diags)

Define Documentation

#define ANALYSIS_CONSTRAINTS (   NAME,
  CMDFLAG,
  DESC,
  CREATFN 
)    .Case(CMDFLAG, NAME##Model)
#define ANALYSIS_DIAGNOSTICS (   NAME,
  CMDFLAG,
  DESC,
  CREATFN 
)    .Case(CMDFLAG, PD_##NAME)
#define ANALYSIS_INLINING_MODE (   NAME,
  CMDFLAG,
  DESC 
)    .Case(CMDFLAG, NAME)
#define ANALYSIS_PURGE (   NAME,
  CMDFLAG,
  DESC 
)    .Case(CMDFLAG, NAME)
#define ANALYSIS_STORE (   NAME,
  CMDFLAG,
  DESC,
  CREATFN 
)    .Case(CMDFLAG, NAME##Model)
#define BENIGN_ENUM_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)
#define BENIGN_LANGOPT (   Name,
  Bits,
  Default,
  Description 
)
#define ENUM_LANGOPT (   Name,
  Type,
  Bits,
  Default,
  Description 
)    code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name()));
#define LANGOPT (   Name,
  Bits,
  Default,
  Description 
)    code = hash_combine(code, LangOpts->Name);
#define LANGSTANDARD (   id,
  name,
  desc,
  features 
)    .Case(name, LangStandard::lang_##id)
#define SANITIZER (   NAME,
  ID 
)    .Case(NAME, SanitizerKind::ID)

Function Documentation

static void addDiagnosticArgs ( ArgList &  Args,
OptSpecifier  Group,
OptSpecifier  GroupWithValue,
std::vector< std::string > &  Diagnostics 
) [static]

Definition at line 114 of file CompilerInvocation.cpp.

static std::shared_ptr<llvm::Regex> GenerateOptimizationRemarkRegex ( DiagnosticsEngine Diags,
ArgList &  Args,
Arg *  RpassArg 
) [static]

Create a new Regex instance out of the string value in RpassArg. It returns a pointer to the newly generated Regex instance.

Definition at line 314 of file CompilerInvocation.cpp.

References clang::DiagnosticsEngine::Report().

Referenced by ParseCodeGenArgs().

static StringRef getCodeModel ( ArgList &  Args,
DiagnosticsEngine Diags 
) [static]

Definition at line 300 of file CompilerInvocation.cpp.

References clang::DiagnosticsEngine::Report().

Referenced by ParseCodeGenArgs().

static unsigned getOptimizationLevel ( ArgList &  Args,
InputKind  IK,
DiagnosticsEngine Diags 
) [static]

Definition at line 73 of file CompilerInvocation.cpp.

References clang::getLastArgIntValue(), clang::IK_OpenCL, and S.

Referenced by ParseCodeGenArgs(), and ParseLangArgs().

static unsigned getOptimizationLevelSize ( ArgList &  Args) [static]

Definition at line 98 of file CompilerInvocation.cpp.

Referenced by ParseCodeGenArgs(), and ParseLangArgs().

static bool ParseAnalyzerArgs ( AnalyzerOptions Opts,
ArgList &  Args,
DiagnosticsEngine Diags 
) [static]
static bool ParseCodeGenArgs ( CodeGenOptions Opts,
ArgList &  Args,
InputKind  IK,
DiagnosticsEngine Diags,
const TargetOptions TargetOpts 
) [static]

Definition at line 327 of file CompilerInvocation.cpp.

References clang::CodeGenOptions::BackendOptions, clang::CodeGenOptions::CodeModel, clang::CodeGenOptions::CoverageFile, clang::CodeGenOptions::CoverageVersion, clang::CodeGenOptions::DebugCompilationDir, clang::CodeGenOptions::DebugLineTablesOnly, clang::CodeGenOptions::DebugPass, clang::CodeGenOptions::DependentLibraries, clang::CodeGenOptions::DwarfDebugFlags, clang::CodeGenOptions::FloatABI, clang::CodeGenOptions::FPC_Fast, clang::CodeGenOptions::FPC_Off, clang::CodeGenOptions::FPC_On, clang::CodeGenOptions::FullDebugInfo, clang::CodeGenOptions::GeneralDynamicTLSModel, GenerateOptimizationRemarkRegex(), getCodeModel(), clang::getLastArgIntValue(), getOptimizationLevel(), getOptimizationLevelSize(), clang::CodeGenOptions::InitialExecTLSModel, clang::CodeGenOptions::InstrProfileInput, clang::CodeGenOptions::Legacy, clang::CodeGenOptions::LimitedDebugInfo, clang::CodeGenOptions::LimitFloatPrecision, clang::CodeGenOptions::LinkBitcodeFile, clang::CodeGenOptions::LocalDynamicTLSModel, clang::CodeGenOptions::LocalExecTLSModel, clang::CodeGenOptions::LocTrackingOnly, clang::CodeGenOptions::MainFileName, clang::CodeGenOptions::Mixed, clang::CodeGenOptions::NoDebugInfo, clang::CodeGenOptions::NonLegacy, clang::CodeGenOptions::NormalInlining, clang::CodeGenOptions::OnlyAlwaysInlining, clang::CodeGenOptions::OptimizationRemarkAnalysisPattern, clang::CodeGenOptions::OptimizationRemarkMissedPattern, clang::CodeGenOptions::OptimizationRemarkPattern, clang::CodeGenOptions::RelocationModel, clang::DiagnosticsEngine::Report(), clang::CodeGenOptions::SampleProfileFile, clang::CodeGenOptions::SplitDwarfFile, clang::CodeGenOptions::SRCK_InRegs, clang::CodeGenOptions::SRCK_OnStack, clang::format::Success, clang::CodeGenOptions::ThreadModel, clang::CodeGenOptions::TrapFuncName, and clang::TargetOptions::Triple.

Referenced by clang::CompilerInvocation::CreateFromArgs().

static void ParseCommentArgs ( CommentOptions Opts,
ArgList &  Args 
) [static]
static void ParseDependencyOutputArgs ( DependencyOutputOptions Opts,
ArgList &  Args 
) [static]
static void ParseFileSystemArgs ( FileSystemOptions Opts,
ArgList &  Args 
) [static]
static InputKind ParseFrontendArgs ( FrontendOptions Opts,
ArgList &  Args,
DiagnosticsEngine Diags 
) [static]

Definition at line 727 of file CompilerInvocation.cpp.

References clang::FrontendOptions::ActionName, clang::FrontendOptions::AddPluginActions, clang::FrontendOptions::AddPluginArgs, clang::FrontendOptions::ARCMT_Check, clang::FrontendOptions::ARCMT_Migrate, clang::FrontendOptions::ARCMT_Modify, clang::FrontendOptions::ARCMT_None, clang::FrontendOptions::ARCMTAction, clang::FrontendOptions::ARCMTMigrateEmitARCErrors, clang::FrontendOptions::ARCMTMigrateReportOut, clang::frontend::ASTDeclList, clang::frontend::ASTDump, clang::FrontendOptions::ASTDumpDecls, clang::FrontendOptions::ASTDumpFilter, clang::FrontendOptions::ASTDumpLookups, clang::FrontendOptions::ASTMergeFiles, clang::frontend::ASTPrint, clang::frontend::ASTView, clang::FrontendOptions::CodeCompleteOpts, clang::FrontendOptions::CodeCompletionAt, clang::FrontendOptions::DisableFree, clang::frontend::DumpRawTokens, clang::frontend::DumpTokens, clang::frontend::EmitAssembly, clang::frontend::EmitBC, clang::frontend::EmitCodeGenOnly, clang::frontend::EmitHTML, clang::frontend::EmitLLVM, clang::frontend::EmitLLVMOnly, clang::frontend::EmitObj, clang::ParsedSourceLocation::FileName, clang::FrontendOptions::FixAndRecompile, clang::frontend::FixIt, clang::FrontendOptions::FixItSuffix, clang::FrontendOptions::FixOnlyWarnings, clang::FrontendOptions::FixToTemporaries, clang::FrontendOptions::FixWhatYouCan, clang::ParsedSourceLocation::FromString(), clang::FrontendOptions::GenerateGlobalModuleIndex, clang::frontend::GenerateModule, clang::frontend::GeneratePCH, clang::frontend::GeneratePTH, clang::FrontendOptions::getInputKindForExtension(), clang::IK_Asm, clang::IK_AST, clang::IK_C, clang::IK_CUDA, clang::IK_CXX, clang::IK_LLVM_IR, clang::IK_None, clang::IK_ObjC, clang::IK_ObjCXX, clang::IK_OpenCL, clang::IK_PreprocessedC, clang::IK_PreprocessedCXX, clang::IK_PreprocessedObjC, clang::IK_PreprocessedObjCXX, CodeCompleteOptions::IncludeBriefComments, CodeCompleteOptions::IncludeCodePatterns, CodeCompleteOptions::IncludeGlobals, CodeCompleteOptions::IncludeMacros, clang::frontend::InitOnly, clang::FrontendOptions::Inputs, clang::FrontendOptions::LLVMArgs, clang::frontend::MigrateSource, clang::frontend::ModuleFileInfo, clang::FrontendOptions::ModuleFiles, clang::FrontendOptions::MTMigrateDir, clang::FrontendOptions::ObjCMT_Annotation, clang::FrontendOptions::ObjCMT_AtomicProperty, clang::FrontendOptions::ObjCMT_DesignatedInitializer, clang::FrontendOptions::ObjCMT_Instancetype, clang::FrontendOptions::ObjCMT_Literals, clang::FrontendOptions::ObjCMT_MigrateDecls, clang::FrontendOptions::ObjCMT_None, clang::FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty, clang::FrontendOptions::ObjCMT_NsMacros, clang::FrontendOptions::ObjCMT_Property, clang::FrontendOptions::ObjCMT_PropertyDotSyntax, clang::FrontendOptions::ObjCMT_ProtocolConformance, clang::FrontendOptions::ObjCMT_ReadonlyProperty, clang::FrontendOptions::ObjCMT_ReadwriteProperty, clang::FrontendOptions::ObjCMT_ReturnsInnerPointerProperty, clang::FrontendOptions::ObjCMT_Subscripting, clang::FrontendOptions::ObjCMTAction, clang::FrontendOptions::ObjCMTWhiteListPath, clang::FrontendOptions::OutputFile, clang::FrontendOptions::OverrideRecordLayoutsFile, clang::frontend::ParseSyntaxOnly, clang::frontend::PluginAction, clang::FrontendOptions::PluginArgs, clang::FrontendOptions::Plugins, clang::frontend::PrintDeclContext, clang::frontend::PrintPreamble, clang::frontend::PrintPreprocessedInput, clang::FrontendOptions::ProgramAction, clang::FrontendOptions::RelocatablePCH, clang::DiagnosticsEngine::Report(), clang::frontend::RewriteMacros, clang::frontend::RewriteObjC, clang::frontend::RewriteTest, clang::frontend::RunAnalysis, clang::frontend::RunPreprocessorOnly, clang::FrontendOptions::ShowHelp, clang::FrontendOptions::ShowStats, clang::FrontendOptions::ShowTimers, clang::FrontendOptions::ShowVersion, clang::FrontendOptions::UseGlobalModuleIndex, and clang::frontend::VerifyPCH.

Referenced by clang::CompilerInvocation::CreateFromArgs().

static void ParseHeaderSearchArgs ( HeaderSearchOptions Opts,
ArgList &  Args 
) [static]
static void ParseLangArgs ( LangOptions Opts,
ArgList &  Args,
InputKind  IK,
DiagnosticsEngine Diags 
) [static]

LANGSTANDARD(IDENT, NAME, DESC, FEATURES)

Parameters:
IDENT- The name of the standard as a C++ identifier.
NAME- The name of the standard.
DESC- A short description of the standard.
FEATURES- The standard features as flags, these are enums from the clang::frontend namespace, which is assumed to be be available.

Definition at line 1268 of file CompilerInvocation.cpp.

References clang::ObjCRuntime::allowsARC(), clang::ObjCRuntime::allowsWeak(), clang::LangOptions::ASMM_Off, clang::LangOptions::ASMM_On, clang::LangOptions::ASMM_Target, clang::LangOptions::CurrentModule, clang::DefaultVisibility, clang::ObjCRuntime::FragileMacOSX, clang::LangOptions::GCOnly, clang::ObjCRuntime::getKind(), clang::LangStandard::getLangStandardForKind(), clang::getLastArgIntValue(), getOptimizationLevel(), getOptimizationLevelSize(), clang::LangOptions::HybridGC, clang::IK_C, clang::IK_CUDA, clang::IK_CXX, clang::IK_ObjC, clang::IK_ObjCXX, clang::IK_OpenCL, clang::IK_PreprocessedC, clang::IK_PreprocessedCXX, clang::IK_PreprocessedObjC, clang::IK_PreprocessedObjCXX, clang::LangOptions::ImplementationOfModule, clang::LangStandard::isC89(), clang::LangStandard::isC99(), clang::LangStandard::isCPlusPlus(), LANGSTANDARD, clang::LangOptions::ObjCConstantStringClass, clang::LangOptions::ObjCRuntime, clang::LangOptions::OverflowHandler, parseMSCVersion(), parseVisibility(), clang::LangOptions::PPTMK_BestCase, clang::LangOptions::PPTMK_FullGeneralityMultipleInheritance, clang::LangOptions::PPTMK_FullGeneralitySingleInheritance, clang::LangOptions::PPTMK_FullGeneralityVirtualInheritance, clang::DiagnosticsEngine::Report(), clang::LangOptions::Sanitize, SANITIZER, clang::LangOptions::SanitizerBlacklistFile, clang::SanitizerSet::set(), clang::CompilerInvocation::setLangDefaults(), clang::LangOptions::SOB_Defined, clang::LangOptions::SOB_Trapping, clang::LangOptions::SSPOff, clang::LangOptions::SSPOn, clang::LangOptions::SSPReq, clang::LangOptions::SSPStrong, clang::ObjCRuntime::tryParse(), and Unknown.

Referenced by clang::CompilerInvocation::CreateFromArgs().

static bool ParseMigratorArgs ( MigratorOptions Opts,
ArgList &  Args 
) [static]
static unsigned parseMSCVersion ( ArgList &  Args,
DiagnosticsEngine Diags 
) [static]

Definition at line 1231 of file CompilerInvocation.cpp.

References clang::DiagnosticsEngine::Report().

Referenced by ParseLangArgs().

static void ParsePreprocessorArgs ( PreprocessorOptions Opts,
ArgList &  Args,
FileManager FileMgr,
DiagnosticsEngine Diags 
) [static]
static void ParsePreprocessorOutputArgs ( PreprocessorOutputOptions Opts,
ArgList &  Args,
frontend::ActionKind  Action 
) [static]
static void ParseTargetArgs ( TargetOptions Opts,
ArgList &  Args 
) [static]
static Visibility parseVisibility ( Arg *  arg,
ArgList &  args,
DiagnosticsEngine diags 
) [static]

Attempt to parse a visibility value out of the given argument.

Definition at line 1214 of file CompilerInvocation.cpp.

References clang::DefaultVisibility, clang::HiddenVisibility, clang::ProtectedVisibility, and clang::DiagnosticsEngine::Report().

Referenced by ParseLangArgs().