clang 22.0.0git
Clang.cpp File Reference
#include "Clang.h"
#include "Arch/ARM.h"
#include "Arch/LoongArch.h"
#include "Arch/Mips.h"
#include "Arch/PPC.h"
#include "Arch/RISCV.h"
#include "Arch/Sparc.h"
#include "Arch/SystemZ.h"
#include "Hexagon.h"
#include "PS4CPU.h"
#include "ToolChains/Cuda.h"
#include "clang/Basic/CLWarnings.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/HeaderInclude.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/MakeSupport.h"
#include "clang/Basic/ObjCRuntime.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/CommonArgs.h"
#include "clang/Driver/Distro.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
#include "clang/Driver/Types.h"
#include "clang/Driver/XRayArgs.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Frontend/Debug/Options.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/TargetParser/AArch64TargetParser.h"
#include "llvm/TargetParser/ARMTargetParserCommon.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/LoongArchTargetParser.h"
#include "llvm/TargetParser/PPCTargetParser.h"
#include "llvm/TargetParser/RISCVISAInfo.h"
#include "llvm/TargetParser/RISCVTargetParser.h"
#include <cctype>

Go to the source code of this file.

Functions

static void CheckPreprocessingOptions (const Driver &D, const ArgList &Args)
static void CheckCodeGenerationOptions (const Driver &D, const ArgList &Args)
static void forAllAssociatedToolChains (Compilation &C, const JobAction &JA, const ToolChain &RegularToolChain, llvm::function_ref< void(const ToolChain &)> Work)
 Apply Work on the current tool chain RegularToolChain and any other offloading tool chain that is associated with the current action JA.
static bool shouldUseExceptionTablesForObjCExceptions (const ObjCRuntime &runtime, const llvm::Triple &Triple)
static bool addExceptionArgs (const ArgList &Args, types::ID InputType, const ToolChain &TC, bool KernelOrKext, const ObjCRuntime &objcRuntime, ArgStringList &CmdArgs)
 Adds exception related arguments to the driver command arguments.
static bool ShouldEnableAutolink (const ArgList &Args, const ToolChain &TC, const JobAction &JA)
static const char * addDebugCompDirArg (const ArgList &Args, ArgStringList &CmdArgs, const llvm::vfs::FileSystem &VFS)
 Add a CC1 option to specify the debug compilation directory.
static void addDebugObjectName (const ArgList &Args, ArgStringList &CmdArgs, const char *DebugCompilationDir, const char *OutputFileName)
static void addDebugPrefixMapArg (const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
 Add a CC1 and CC1AS option to specify the debug file path prefix map.
static void addMacroPrefixMapArg (const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
 Add a CC1 and CC1AS option to specify the macro file path prefix map.
static void addCoveragePrefixMapArg (const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
 Add a CC1 and CC1AS option to specify the coverage file path prefix map.
static void addDashXForInput (const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
 Add -x lang to CmdArgs for Input.
static void addPGOAndCoverageFlags (const ToolChain &TC, Compilation &C, const JobAction &JA, const InputInfo &Output, const ArgList &Args, SanitizerArgs &SanArgs, ArgStringList &CmdArgs)
static void RenderDebugEnablingArgs (const ArgList &Args, ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind, unsigned DwarfVersion, llvm::DebuggerKind DebuggerTuning)
static bool checkDebugInfoOption (const Arg *A, const ArgList &Args, const Driver &D, const ToolChain &TC)
static void RenderDebugInfoCompressionArgs (const ArgList &Args, ArgStringList &CmdArgs, const Driver &D, const ToolChain &TC)
static void handleAMDGPUCodeObjectVersionOptions (const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, bool IsCC1As=false)
static bool maybeHasClangPchSignature (const Driver &D, StringRef Path)
static bool gchProbe (const Driver &D, StringRef Path)
static bool isSignedCharDefault (const llvm::Triple &Triple)
static bool hasMultipleInvocations (const llvm::Triple &Triple, const ArgList &Args)
static bool checkRemarksOptions (const Driver &D, const ArgList &Args, const llvm::Triple &Triple)
static void renderRemarksOptions (const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
void AddAAPCSVolatileBitfieldArgs (const ArgList &Args, ArgStringList &CmdArgs)
static void handlePAuthABI (const ArgList &DriverArgs, ArgStringList &CC1Args)
static void CollectARMPACBTIOptions (const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool isAArch64)
static bool CheckARMImplicitITArg (StringRef Value)
static void AddARMImplicitITArgs (const ArgList &Args, ArgStringList &CmdArgs, StringRef Value)
static void CollectArgsForIntegratedAssembler (Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const Driver &D)
static void EmitComplexRangeDiag (const Driver &D, StringRef LastOpt, LangOptions::ComplexRangeKind Range, StringRef NewOpt, LangOptions::ComplexRangeKind NewRange)
static void RenderFloatingPointOptions (const ToolChain &TC, const Driver &D, bool OFastEnabled, const ArgList &Args, ArgStringList &CmdArgs, const JobAction &JA)
static void RenderAnalyzerOptions (const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input)
static bool isValidSymbolName (StringRef S)
static void RenderSSPOptions (const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool KernelOrKext)
static void RenderSCPOptions (const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderTrivialAutoVarInitOptions (const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderOpenCLOptions (const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void RenderHLSLOptions (const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void RenderOpenACCOptions (const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void RenderBuiltinOptions (const ToolChain &TC, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs)
static bool RenderModulesOptions (Compilation &C, const Driver &D, const ArgList &Args, const InputInfo &Input, const InputInfo &Output, bool HaveStd20, ArgStringList &CmdArgs)
static void RenderCharacterOptions (const ArgList &Args, const llvm::Triple &T, ArgStringList &CmdArgs)
static void RenderObjCOptions (const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, ObjCRuntime &Runtime, bool InferCovariantReturns, const InputInfo &Input, ArgStringList &CmdArgs)
static void RenderDiagnosticsOptions (const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
static void renderDwarfFormat (const Driver &D, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs, unsigned DwarfVersion)
static void renderDebugOptions (const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, types::ID InputType, ArgStringList &CmdArgs, const InputInfo &Output, llvm::codegenoptions::DebugInfoKind &DebugInfoKind, DwarfFissionKind &DwarfFission)
static void ProcessVSRuntimeLibrary (const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static bool maybeConsumeDash (const std::string &EH, size_t &I)
static EHFlags parseClangCLEHFlags (const Driver &D, const ArgList &Args, bool isWindowsMSVC)
 /EH controls whether to run destructor cleanups when exceptions are thrown.

Function Documentation

◆ AddAAPCSVolatileBitfieldArgs()

void AddAAPCSVolatileBitfieldArgs ( const ArgList & Args,
ArgStringList & CmdArgs )

Definition at line 1307 of file Clang.cpp.

◆ AddARMImplicitITArgs()

void AddARMImplicitITArgs ( const ArgList & Args,
ArgStringList & CmdArgs,
StringRef Value )
static

Definition at line 2402 of file Clang.cpp.

Referenced by CollectArgsForIntegratedAssembler().

◆ addCoveragePrefixMapArg()

void addCoveragePrefixMapArg ( const Driver & D,
const ArgList & Args,
ArgStringList & CmdArgs )
static

Add a CC1 and CC1AS option to specify the coverage file path prefix map.

Definition at line 316 of file Clang.cpp.

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

◆ addDashXForInput()

void addDashXForInput ( const ArgList & Args,
const InputInfo & Input,
ArgStringList & CmdArgs )
static

◆ addDebugCompDirArg()

const char * addDebugCompDirArg ( const ArgList & Args,
ArgStringList & CmdArgs,
const llvm::vfs::FileSystem & VFS )
static

Add a CC1 option to specify the debug compilation directory.

Definition at line 226 of file Clang.cpp.

Referenced by clang::driver::tools::ClangAs::ConstructJob(), and renderDebugOptions().

◆ addDebugObjectName()

void addDebugObjectName ( const ArgList & Args,
ArgStringList & CmdArgs,
const char * DebugCompilationDir,
const char * OutputFileName )
static

Definition at line 246 of file Clang.cpp.

Referenced by clang::driver::tools::ClangAs::ConstructJob(), and renderDebugOptions().

◆ addDebugPrefixMapArg()

void addDebugPrefixMapArg ( const Driver & D,
const ToolChain & TC,
const ArgList & Args,
ArgStringList & CmdArgs )
static

Add a CC1 and CC1AS option to specify the debug file path prefix map.

Definition at line 280 of file Clang.cpp.

References clang::driver::Driver::Diag(), and clang::driver::ToolChain::GetGlobalDebugPathRemapping().

Referenced by clang::driver::tools::ClangAs::ConstructJob(), and renderDebugOptions().

◆ addExceptionArgs()

bool addExceptionArgs ( const ArgList & Args,
types::ID InputType,
const ToolChain & TC,
bool KernelOrKext,
const ObjCRuntime & objcRuntime,
ArgStringList & CmdArgs )
static

Adds exception related arguments to the driver command arguments.

There's a main flag, -fexceptions and also language specific flags to enable/disable C++ and Objective-C exceptions. This makes it possible to for example disable C++ exceptions but enable Objective-C exceptions.

Definition at line 133 of file Clang.cpp.

References clang::driver::ToolChain::getTriple(), clang::driver::types::isCXX(), clang::driver::types::isObjC(), and shouldUseExceptionTablesForObjCExceptions().

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ addMacroPrefixMapArg()

void addMacroPrefixMapArg ( const Driver & D,
const ArgList & Args,
ArgStringList & CmdArgs )
static

Add a CC1 and CC1AS option to specify the macro file path prefix map.

Definition at line 301 of file Clang.cpp.

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

◆ addPGOAndCoverageFlags()

◆ CheckARMImplicitITArg()

bool CheckARMImplicitITArg ( StringRef Value)
static

Definition at line 2397 of file Clang.cpp.

Referenced by CollectArgsForIntegratedAssembler().

◆ CheckCodeGenerationOptions()

void CheckCodeGenerationOptions ( const Driver & D,
const ArgList & Args )
static

Definition at line 81 of file Clang.cpp.

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

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ checkDebugInfoOption()

bool checkDebugInfoOption ( const Arg * A,
const ArgList & Args,
const Driver & D,
const ToolChain & TC )
static

◆ CheckPreprocessingOptions()

void CheckPreprocessingOptions ( const Driver & D,
const ArgList & Args )
static

◆ checkRemarksOptions()

bool checkRemarksOptions ( const Driver & D,
const ArgList & Args,
const llvm::Triple & Triple )
static

◆ CollectArgsForIntegratedAssembler()

◆ CollectARMPACBTIOptions()

void CollectARMPACBTIOptions ( const ToolChain & TC,
const ArgList & Args,
ArgStringList & CmdArgs,
bool isAArch64 )
static

◆ EmitComplexRangeDiag()

void EmitComplexRangeDiag ( const Driver & D,
StringRef LastOpt,
LangOptions::ComplexRangeKind Range,
StringRef NewOpt,
LangOptions::ComplexRangeKind NewRange )
static

◆ forAllAssociatedToolChains()

void forAllAssociatedToolChains ( Compilation & C,
const JobAction & JA,
const ToolChain & RegularToolChain,
llvm::function_ref< void(const ToolChain &)> Work )
static

Apply Work on the current tool chain RegularToolChain and any other offloading tool chain that is associated with the current action JA.

Definition at line 93 of file Clang.cpp.

References clang::C, clang::driver::Action::isDeviceOffloading(), clang::driver::Action::isHostOffloading(), clang::driver::Action::OFK_Cuda, clang::driver::Action::OFK_HIP, clang::driver::Action::OFK_Host, clang::driver::Action::OFK_OpenMP, and clang::driver::Action::OFK_SYCL.

Referenced by clang::driver::tools::LinkerWrapper::ConstructJob().

◆ gchProbe()

bool gchProbe ( const Driver & D,
StringRef Path )
static

◆ handleAMDGPUCodeObjectVersionOptions()

void handleAMDGPUCodeObjectVersionOptions ( const Driver & D,
const ArgList & Args,
ArgStringList & CmdArgs,
bool IsCC1As = false )
static

◆ handlePAuthABI()

void handlePAuthABI ( const ArgList & DriverArgs,
ArgStringList & CC1Args )
static

Definition at line 1346 of file Clang.cpp.

◆ hasMultipleInvocations()

bool hasMultipleInvocations ( const llvm::Triple & Triple,
const ArgList & Args )
static

Definition at line 1197 of file Clang.cpp.

Referenced by checkRemarksOptions(), and checkRemarksOptions().

◆ isSignedCharDefault()

bool isSignedCharDefault ( const llvm::Triple & Triple)
static

Definition at line 1161 of file Clang.cpp.

Referenced by RenderCharacterOptions().

◆ isValidSymbolName()

bool isValidSymbolName ( StringRef S)
static

Definition at line 3446 of file Clang.cpp.

References clang::C.

Referenced by RenderSSPOptions().

◆ maybeConsumeDash()

bool maybeConsumeDash ( const std::string & EH,
size_t & I )
static

Definition at line 8186 of file Clang.cpp.

Referenced by parseClangCLEHFlags().

◆ maybeHasClangPchSignature()

bool maybeHasClangPchSignature ( const Driver & D,
StringRef Path )
static

Definition at line 763 of file Clang.cpp.

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

Referenced by gchProbe().

◆ parseClangCLEHFlags()

EHFlags parseClangCLEHFlags ( const Driver & D,
const ArgList & Args,
bool isWindowsMSVC )
static

/EH controls whether to run destructor cleanups when exceptions are thrown.

There are three modifiers:

  • s: Cleanup after "synchronous" exceptions, aka C++ exceptions.
  • a: Cleanup after "asynchronous" exceptions, aka structured exceptions. The 'a' modifier is unimplemented and fundamentally hard in LLVM IR.
  • c: Assume that extern "C" functions are implicitly nounwind. The default is /EHs-c-, meaning cleanups are disabled.

Definition at line 8207 of file Clang.cpp.

References clang::driver::Driver::Diag(), and maybeConsumeDash().

◆ ProcessVSRuntimeLibrary()

void ProcessVSRuntimeLibrary ( const ToolChain & TC,
const ArgList & Args,
ArgStringList & CmdArgs )
static

◆ RenderAnalyzerOptions()

void RenderAnalyzerOptions ( const ArgList & Args,
ArgStringList & CmdArgs,
const llvm::Triple & Triple,
const InputInfo & Input )
static

◆ RenderBuiltinOptions()

void RenderBuiltinOptions ( const ToolChain & TC,
const llvm::Triple & T,
const ArgList & Args,
ArgStringList & CmdArgs )
static

Definition at line 3804 of file Clang.cpp.

References clang::T.

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ RenderCharacterOptions()

void RenderCharacterOptions ( const ArgList & Args,
const llvm::Triple & T,
ArgStringList & CmdArgs )
static

Definition at line 4102 of file Clang.cpp.

References isSignedCharDefault(), and clang::T.

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ RenderDebugEnablingArgs()

void RenderDebugEnablingArgs ( const ArgList & Args,
ArgStringList & CmdArgs,
llvm::codegenoptions::DebugInfoKind DebugInfoKind,
unsigned DwarfVersion,
llvm::DebuggerKind DebuggerTuning )
static

◆ RenderDebugInfoCompressionArgs()

void RenderDebugInfoCompressionArgs ( const ArgList & Args,
ArgStringList & CmdArgs,
const Driver & D,
const ToolChain & TC )
static

◆ renderDebugOptions()

◆ RenderDiagnosticsOptions()

void RenderDiagnosticsOptions ( const Driver & D,
const ArgList & Args,
ArgStringList & CmdArgs )
static

◆ renderDwarfFormat()

void renderDwarfFormat ( const Driver & D,
const llvm::Triple & T,
const ArgList & Args,
ArgStringList & CmdArgs,
unsigned DwarfVersion )
static

◆ RenderFloatingPointOptions()

◆ RenderHLSLOptions()

void RenderHLSLOptions ( const ArgList & Args,
ArgStringList & CmdArgs,
types::ID InputType )
static

Definition at line 3769 of file Clang.cpp.

References clang::driver::types::isHLSL().

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ RenderModulesOptions()

◆ RenderObjCOptions()

◆ RenderOpenACCOptions()

void RenderOpenACCOptions ( const Driver & D,
const ArgList & Args,
ArgStringList & CmdArgs,
types::ID InputType )
static

Definition at line 3796 of file Clang.cpp.

Referenced by clang::driver::tools::Clang::ConstructJob().

◆ RenderOpenCLOptions()

void RenderOpenCLOptions ( const ArgList & Args,
ArgStringList & CmdArgs,
types::ID InputType )
static

◆ renderRemarksOptions()

◆ RenderSCPOptions()

void RenderSCPOptions ( const ToolChain & TC,
const ArgList & Args,
ArgStringList & CmdArgs )
static

◆ RenderSSPOptions()

◆ RenderTrivialAutoVarInitOptions()

void RenderTrivialAutoVarInitOptions ( const Driver & D,
const ToolChain & TC,
const ArgList & Args,
ArgStringList & CmdArgs )
static

◆ ShouldEnableAutolink()

◆ shouldUseExceptionTablesForObjCExceptions()

bool shouldUseExceptionTablesForObjCExceptions ( const ObjCRuntime & runtime,
const llvm::Triple & Triple )
static

Definition at line 113 of file Clang.cpp.

References clang::ObjCRuntime::isNonFragile().

Referenced by addExceptionArgs().