#include "clang/Frontend/CompilerInvocation.h"
#include "TestModuleFileExtension.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/CommentOptions.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/Version.h"
#include "clang/Basic/Visibility.h"
#include "clang/Basic/XRayInstr.h"
#include "clang/Config/config.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/CommandLineSourceLoc.h"
#include "clang/Frontend/DependencyOutputOptions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/Frontend/MigratorOptions.h"
#include "clang/Frontend/PreprocessorOutputOptions.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Frontend/Utils.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/CodeCompleteOptions.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "clang/Serialization/ModuleFileExtension.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/FloatingPointMode.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Linker/Linker.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptSpecifier.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Option/Option.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/HashBuilder.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <atomic>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <ctime>
#include <fstream>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
usingnamespaceclang;
usingnamespacedriver;
usingnamespaceoptions;
usingnamespacellvm::opt;
static Expected<std::optional<uint32_t>> parseToleranceOption(StringRef Arg) { … }
namespace {
template <class T> std::shared_ptr<T> make_shared_copy(const T &X) { … }
template <class T>
llvm::IntrusiveRefCntPtr<T> makeIntrusiveRefCntCopy(const T &X) { … }
}
CompilerInvocationBase::CompilerInvocationBase()
: … { … }
CompilerInvocationBase &
CompilerInvocationBase::deep_copy_assign(const CompilerInvocationBase &X) { … }
CompilerInvocationBase &
CompilerInvocationBase::shallow_copy_assign(const CompilerInvocationBase &X) { … }
CompilerInvocation::CompilerInvocation(const CowCompilerInvocation &X)
: … { … }
CompilerInvocation &
CompilerInvocation::operator=(const CowCompilerInvocation &X) { … }
namespace {
template <typename T>
T &ensureOwned(std::shared_ptr<T> &Storage) { … }
template <typename T>
T &ensureOwned(llvm::IntrusiveRefCntPtr<T> &Storage) { … }
}
LangOptions &CowCompilerInvocation::getMutLangOpts() { … }
TargetOptions &CowCompilerInvocation::getMutTargetOpts() { … }
DiagnosticOptions &CowCompilerInvocation::getMutDiagnosticOpts() { … }
HeaderSearchOptions &CowCompilerInvocation::getMutHeaderSearchOpts() { … }
PreprocessorOptions &CowCompilerInvocation::getMutPreprocessorOpts() { … }
AnalyzerOptions &CowCompilerInvocation::getMutAnalyzerOpts() { … }
MigratorOptions &CowCompilerInvocation::getMutMigratorOpts() { … }
APINotesOptions &CowCompilerInvocation::getMutAPINotesOpts() { … }
CodeGenOptions &CowCompilerInvocation::getMutCodeGenOpts() { … }
FileSystemOptions &CowCompilerInvocation::getMutFileSystemOpts() { … }
FrontendOptions &CowCompilerInvocation::getMutFrontendOpts() { … }
DependencyOutputOptions &CowCompilerInvocation::getMutDependencyOutputOpts() { … }
PreprocessorOutputOptions &
CowCompilerInvocation::getMutPreprocessorOutputOpts() { … }
ArgumentConsumer;
#define SIMPLE_ENUM_VALUE_TABLE
#include "clang/Driver/Options.inc"
#undef SIMPLE_ENUM_VALUE_TABLE
static std::optional<bool> normalizeSimpleFlag(OptSpecifier Opt,
unsigned TableIndex,
const ArgList &Args,
DiagnosticsEngine &Diags) { … }
static std::optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt,
unsigned,
const ArgList &Args,
DiagnosticsEngine &) { … }
static void denormalizeSimpleFlag(ArgumentConsumer Consumer,
const Twine &Spelling, Option::OptionClass,
unsigned, ...) { … }
template <typename T> static constexpr bool is_uint64_t_convertible() { … }
template <typename T,
std::enable_if_t<!is_uint64_t_convertible<T>(), bool> = false>
static auto makeFlagToValueNormalizer(T Value) { … }
template <typename T,
std::enable_if_t<is_uint64_t_convertible<T>(), bool> = false>
static auto makeFlagToValueNormalizer(T Value) { … }
static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
OptSpecifier OtherOpt) { … }
static auto makeBooleanOptionDenormalizer(bool Value) { … }
static void denormalizeStringImpl(ArgumentConsumer Consumer,
const Twine &Spelling,
Option::OptionClass OptClass, unsigned,
const Twine &Value) { … }
template <typename T>
static void denormalizeString(ArgumentConsumer Consumer, const Twine &Spelling,
Option::OptionClass OptClass, unsigned TableIndex,
T Value) { … }
static std::optional<SimpleEnumValue>
findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) { … }
static std::optional<SimpleEnumValue>
findValueTableByValue(const SimpleEnumValueTable &Table, unsigned Value) { … }
static std::optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
unsigned TableIndex,
const ArgList &Args,
DiagnosticsEngine &Diags) { … }
static void denormalizeSimpleEnumImpl(ArgumentConsumer Consumer,
const Twine &Spelling,
Option::OptionClass OptClass,
unsigned TableIndex, unsigned Value) { … }
template <typename T>
static void denormalizeSimpleEnum(ArgumentConsumer Consumer,
const Twine &Spelling,
Option::OptionClass OptClass,
unsigned TableIndex, T Value) { … }
static std::optional<std::string> normalizeString(OptSpecifier Opt,
int TableIndex,
const ArgList &Args,
DiagnosticsEngine &Diags) { … }
template <typename IntTy>
static std::optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
const ArgList &Args,
DiagnosticsEngine &Diags) { … }
static std::optional<std::vector<std::string>>
normalizeStringVector(OptSpecifier Opt, int, const ArgList &Args,
DiagnosticsEngine &) { … }
static void denormalizeStringVector(ArgumentConsumer Consumer,
const Twine &Spelling,
Option::OptionClass OptClass,
unsigned TableIndex,
const std::vector<std::string> &Values) { … }
static std::optional<std::string> normalizeTriple(OptSpecifier Opt,
int TableIndex,
const ArgList &Args,
DiagnosticsEngine &Diags) { … }
template <typename T, typename U>
static T mergeForwardValue(T KeyPath, U Value) { … }
template <typename T, typename U> static T mergeMaskValue(T KeyPath, U Value) { … }
template <typename T> static T extractForwardValue(T KeyPath) { … }
template <typename T, typename U, U Value>
static T extractMaskValue(T KeyPath) { … }
#define PARSE_OPTION_WITH_MARSHALLING( \
ARGS, DIAGS, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \
FLAGS, VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \
SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) …
#define GENERATE_OPTION_WITH_MARSHALLING( \
CONSUMER, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
VISIBILITY, PARAM, HELPTEXT, HELPTEXTSFORVARIANTS, METAVAR, VALUES, \
SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, \
IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) …
static StringRef GetInputKindName(InputKind IK);
static bool FixupInvocation(CompilerInvocation &Invocation,
DiagnosticsEngine &Diags, const ArgList &Args,
InputKind IK) { … }
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
DiagnosticsEngine &Diags) { … }
static unsigned getOptimizationLevelSize(ArgList &Args) { … }
static void GenerateArg(ArgumentConsumer Consumer,
llvm::opt::OptSpecifier OptSpecifier) { … }
static void GenerateArg(ArgumentConsumer Consumer,
llvm::opt::OptSpecifier OptSpecifier,
const Twine &Value) { … }
ParseFn;
GenerateFn;
static bool RoundTrip(ParseFn Parse, GenerateFn Generate,
CompilerInvocation &RealInvocation,
CompilerInvocation &DummyInvocation,
ArrayRef<const char *> CommandLineArgs,
DiagnosticsEngine &Diags, const char *Argv0,
bool CheckAgainstOriginalInvocation = false,
bool ForceRoundTrip = false) { … }
bool CompilerInvocation::checkCC1RoundTrip(ArrayRef<const char *> Args,
DiagnosticsEngine &Diags,
const char *Argv0) { … }
static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
OptSpecifier GroupWithValue,
std::vector<std::string> &Diagnostics) { … }
static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
DiagnosticsEngine *Diags);
static void getAllNoBuiltinFuncValues(ArgList &Args,
std::vector<std::string> &Funcs) { … }
static void GenerateAnalyzerArgs(const AnalyzerOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) { … }
static StringRef getStringOption(AnalyzerOptions::ConfigTable &Config,
StringRef OptionName, StringRef DefaultVal) { … }
static void initOption(AnalyzerOptions::ConfigTable &Config,
DiagnosticsEngine *Diags,
StringRef &OptionField, StringRef Name,
StringRef DefaultVal) { … }
static void initOption(AnalyzerOptions::ConfigTable &Config,
DiagnosticsEngine *Diags,
bool &OptionField, StringRef Name, bool DefaultVal) { … }
static void initOption(AnalyzerOptions::ConfigTable &Config,
DiagnosticsEngine *Diags,
unsigned &OptionField, StringRef Name,
unsigned DefaultVal) { … }
static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
DiagnosticsEngine *Diags) { … }
static void
GenerateOptimizationRemark(ArgumentConsumer Consumer, OptSpecifier OptEQ,
StringRef Name,
const CodeGenOptions::OptRemark &Remark) { … }
static CodeGenOptions::OptRemark
ParseOptimizationRemark(DiagnosticsEngine &Diags, ArgList &Args,
OptSpecifier OptEQ, StringRef Name) { … }
static bool parseDiagnosticLevelMask(StringRef FlagName,
const std::vector<std::string> &Levels,
DiagnosticsEngine &Diags,
DiagnosticLevelMask &M) { … }
static void parseSanitizerKinds(StringRef FlagName,
const std::vector<std::string> &Sanitizers,
DiagnosticsEngine &Diags, SanitizerSet &S) { … }
static SmallVector<StringRef, 4> serializeSanitizerKinds(SanitizerSet S) { … }
static void parseXRayInstrumentationBundle(StringRef FlagName, StringRef Bundle,
ArgList &Args, DiagnosticsEngine &D,
XRayInstrSet &S) { … }
static std::string serializeXRayInstrumentationBundle(const XRayInstrSet &S) { … }
static void setPGOUseInstrumentor(CodeGenOptions &Opts,
const Twine &ProfileName,
llvm::vfs::FileSystem &FS,
DiagnosticsEngine &Diags) { … }
void CompilerInvocation::setDefaultPointerAuthOptions(
PointerAuthOptions &Opts, const LangOptions &LangOpts,
const llvm::Triple &Triple) { … }
static void parsePointerAuthOptions(PointerAuthOptions &Opts,
const LangOptions &LangOpts,
const llvm::Triple &Triple,
DiagnosticsEngine &Diags) { … }
void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
ArgumentConsumer Consumer,
const llvm::Triple &T,
const std::string &OutputFile,
const LangOptions *LangOpts) { … }
bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
InputKind IK,
DiagnosticsEngine &Diags,
const llvm::Triple &T,
const std::string &OutputFile,
const LangOptions &LangOptsRef) { … }
static void GenerateDependencyOutputArgs(const DependencyOutputOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
ArgList &Args, DiagnosticsEngine &Diags,
frontend::ActionKind Action,
bool ShowLineMarkers) { … }
static bool parseShowColorsArgs(const ArgList &Args, bool DefaultColor) { … }
static bool checkVerifyPrefixes(const std::vector<std::string> &VerifyPrefixes,
DiagnosticsEngine &Diags) { … }
static void GenerateFileSystemArgs(const FileSystemOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseFileSystemArgs(FileSystemOptions &Opts, const ArgList &Args,
DiagnosticsEngine &Diags) { … }
static void GenerateMigratorArgs(const MigratorOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseMigratorArgs(MigratorOptions &Opts, const ArgList &Args,
DiagnosticsEngine &Diags) { … }
void CompilerInvocationBase::GenerateDiagnosticArgs(
const DiagnosticOptions &Opts, ArgumentConsumer Consumer,
bool DefaultDiagColor) { … }
std::unique_ptr<DiagnosticOptions>
clang::CreateAndPopulateDiagOpts(ArrayRef<const char *> Argv) { … }
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticsEngine *Diags,
bool DefaultDiagColor) { … }
static bool parseTestModuleFileExtensionArg(StringRef Arg,
std::string &BlockName,
unsigned &MajorVersion,
unsigned &MinorVersion,
bool &Hashed,
std::string &UserInfo) { … }
static const auto &getFrontendActionTable() { … }
static std::optional<frontend::ActionKind>
getFrontendAction(OptSpecifier &Opt) { … }
static std::optional<OptSpecifier>
getProgramActionOpt(frontend::ActionKind ProgramAction) { … }
static void GenerateFrontendArgs(const FrontendOptions &Opts,
ArgumentConsumer Consumer, bool IsHeader) { … }
static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags, bool &IsHeaderFile) { … }
std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
void *MainAddr) { … }
static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags,
const std::string &WorkingDir) { … }
static void GenerateAPINotesArgs(const APINotesOptions &Opts,
ArgumentConsumer Consumer) { … }
static void ParseAPINotesArgs(APINotesOptions &Opts, ArgList &Args,
DiagnosticsEngine &diags) { … }
static void GeneratePointerAuthArgs(const LangOptions &Opts,
ArgumentConsumer Consumer) { … }
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) { … }
static bool IsInputCompatibleWithStandard(InputKind IK,
const LangStandard &S) { … }
static StringRef GetInputKindName(InputKind IK) { … }
void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
ArgumentConsumer Consumer,
const llvm::Triple &T,
InputKind IK) { … }
bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
InputKind IK, const llvm::Triple &T,
std::vector<std::string> &Includes,
DiagnosticsEngine &Diags) { … }
static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) { … }
static void GeneratePreprocessorArgs(const PreprocessorOptions &Opts,
ArgumentConsumer Consumer,
const LangOptions &LangOpts,
const FrontendOptions &FrontendOpts,
const CodeGenOptions &CodeGenOpts) { … }
static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags,
frontend::ActionKind Action,
const FrontendOptions &FrontendOpts) { … }
static void
GeneratePreprocessorOutputArgs(const PreprocessorOutputOptions &Opts,
ArgumentConsumer Consumer,
frontend::ActionKind Action) { … }
static bool ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
ArgList &Args, DiagnosticsEngine &Diags,
frontend::ActionKind Action) { … }
static void GenerateTargetArgs(const TargetOptions &Opts,
ArgumentConsumer Consumer) { … }
static bool ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) { … }
bool CompilerInvocation::CreateFromArgsImpl(
CompilerInvocation &Res, ArrayRef<const char *> CommandLineArgs,
DiagnosticsEngine &Diags, const char *Argv0) { … }
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Invocation,
ArrayRef<const char *> CommandLineArgs,
DiagnosticsEngine &Diags,
const char *Argv0) { … }
std::string CompilerInvocation::getModuleHash() const { … }
void CompilerInvocationBase::generateCC1CommandLine(
ArgumentConsumer Consumer) const { … }
std::vector<std::string> CompilerInvocationBase::getCC1CommandLine() const { … }
void CompilerInvocation::resetNonModularOptions() { … }
void CompilerInvocation::clearImplicitModuleBuildOptions() { … }
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
clang::createVFSFromCompilerInvocation(const CompilerInvocation &CI,
DiagnosticsEngine &Diags) { … }
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
clang::createVFSFromCompilerInvocation(
const CompilerInvocation &CI, DiagnosticsEngine &Diags,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) { … }
IntrusiveRefCntPtr<llvm::vfs::FileSystem> clang::createVFSFromOverlayFiles(
ArrayRef<std::string> VFSOverlayFiles, DiagnosticsEngine &Diags,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) { … }