aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp460
1 files changed, 295 insertions, 165 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp b/contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp
index f09d1129b128..7ad26ace328a 100644
--- a/contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/contrib/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp
@@ -28,6 +28,7 @@
#include "CoverageMappingGen.h"
#include "TargetInfo.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTLambda.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
@@ -224,9 +225,9 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
StringRef ABIStr = Target.getABI();
unsigned XLen = Target.getPointerWidth(LangAS::Default);
unsigned ABIFLen = 0;
- if (ABIStr.endswith("f"))
+ if (ABIStr.ends_with("f"))
ABIFLen = 32;
- else if (ABIStr.endswith("d"))
+ else if (ABIStr.ends_with("d"))
ABIFLen = 64;
return createRISCVTargetCodeGenInfo(CGM, XLen, ABIFLen);
}
@@ -307,9 +308,9 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
case llvm::Triple::loongarch64: {
StringRef ABIStr = Target.getABI();
unsigned ABIFRLen = 0;
- if (ABIStr.endswith("f"))
+ if (ABIStr.ends_with("f"))
ABIFRLen = 32;
- else if (ABIStr.endswith("d"))
+ else if (ABIStr.ends_with("d"))
ABIFRLen = 64;
return createLoongArchTargetCodeGenInfo(
CGM, Target.getPointerWidth(LangAS::Default), ABIFRLen);
@@ -360,13 +361,14 @@ CodeGenModule::CodeGenModule(ASTContext &C,
IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
IntPtrTy = llvm::IntegerType::get(LLVMContext,
C.getTargetInfo().getMaxPointerWidth());
- Int8PtrTy = Int8Ty->getPointerTo(0);
- Int8PtrPtrTy = Int8PtrTy->getPointerTo(0);
+ Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
const llvm::DataLayout &DL = M.getDataLayout();
- AllocaInt8PtrTy = Int8Ty->getPointerTo(DL.getAllocaAddrSpace());
- GlobalsInt8PtrTy = Int8Ty->getPointerTo(DL.getDefaultGlobalsAddressSpace());
- ConstGlobalsPtrTy = Int8Ty->getPointerTo(
- C.getTargetAddressSpace(GetGlobalConstantAddressSpace()));
+ AllocaInt8PtrTy =
+ llvm::PointerType::get(LLVMContext, DL.getAllocaAddrSpace());
+ GlobalsInt8PtrTy =
+ llvm::PointerType::get(LLVMContext, DL.getDefaultGlobalsAddressSpace());
+ ConstGlobalsPtrTy = llvm::PointerType::get(
+ LLVMContext, C.getTargetAddressSpace(GetGlobalConstantAddressSpace()));
ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
// Build C++20 Module initializers.
@@ -563,8 +565,8 @@ static const llvm::GlobalValue *getAliasedGlobal(const llvm::GlobalValue *GV) {
}
static bool checkAliasedGlobal(
- DiagnosticsEngine &Diags, SourceLocation Location, bool IsIFunc,
- const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
+ const ASTContext &Context, DiagnosticsEngine &Diags, SourceLocation Location,
+ bool IsIFunc, const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
const llvm::MapVector<GlobalDecl, StringRef> &MangledDeclNames,
SourceRange AliasRange) {
GV = getAliasedGlobal(Alias);
@@ -573,6 +575,14 @@ static bool checkAliasedGlobal(
return false;
}
+ if (GV->hasCommonLinkage()) {
+ const llvm::Triple &Triple = Context.getTargetInfo().getTriple();
+ if (Triple.getObjectFormat() == llvm::Triple::XCOFF) {
+ Diags.Report(Location, diag::err_alias_to_common);
+ return false;
+ }
+ }
+
if (GV->isDeclaration()) {
Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
Diags.Report(Location, diag::note_alias_requires_mangled_name)
@@ -633,7 +643,7 @@ void CodeGenModule::checkAliases() {
StringRef MangledName = getMangledName(GD);
llvm::GlobalValue *Alias = GetGlobalValue(MangledName);
const llvm::GlobalValue *GV = nullptr;
- if (!checkAliasedGlobal(Diags, Location, IsIFunc, Alias, GV,
+ if (!checkAliasedGlobal(getContext(), Diags, Location, IsIFunc, Alias, GV,
MangledDeclNames, Range)) {
Error = true;
continue;
@@ -689,6 +699,7 @@ void CodeGenModule::checkAliases() {
void CodeGenModule::clear() {
DeferredDeclsToEmit.clear();
EmittedDeferredDecls.clear();
+ DeferredAnnotations.clear();
if (OpenMPRuntime)
OpenMPRuntime->clear();
}
@@ -752,6 +763,14 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
}
}
+static bool isStackProtectorOn(const LangOptions &LangOpts,
+ const llvm::Triple &Triple,
+ clang::LangOptions::StackProtectorMode Mode) {
+ if (Triple.isAMDGPU() || Triple.isNVPTX())
+ return false;
+ return LangOpts.getStackProtector() == Mode;
+}
+
void CodeGenModule::Release() {
Module *Primary = getContext().getCurrentNamedModule();
if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule())
@@ -829,7 +848,7 @@ void CodeGenModule::Release() {
// Emit amdgpu_code_object_version module flag, which is code object version
// times 100.
if (getTarget().getTargetOpts().CodeObjectVersion !=
- TargetOptions::COV_None) {
+ llvm::CodeObjectVersionKind::COV_None) {
getModule().addModuleFlag(llvm::Module::Error,
"amdgpu_code_object_version",
getTarget().getTargetOpts().CodeObjectVersion);
@@ -967,6 +986,41 @@ void CodeGenModule::Release() {
Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
+ if (getTriple().isOSzOS()) {
+ getModule().addModuleFlag(llvm::Module::Warning,
+ "zos_product_major_version",
+ uint32_t(CLANG_VERSION_MAJOR));
+ getModule().addModuleFlag(llvm::Module::Warning,
+ "zos_product_minor_version",
+ uint32_t(CLANG_VERSION_MINOR));
+ getModule().addModuleFlag(llvm::Module::Warning, "zos_product_patchlevel",
+ uint32_t(CLANG_VERSION_PATCHLEVEL));
+ std::string ProductId;
+#ifdef CLANG_VENDOR
+ ProductId = #CLANG_VENDOR;
+#else
+ ProductId = "clang";
+#endif
+ getModule().addModuleFlag(llvm::Module::Error, "zos_product_id",
+ llvm::MDString::get(VMContext, ProductId));
+
+ // Record the language because we need it for the PPA2.
+ StringRef lang_str = languageToString(
+ LangStandard::getLangStandardForKind(LangOpts.LangStd).Language);
+ getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language",
+ llvm::MDString::get(VMContext, lang_str));
+
+ time_t TT = PreprocessorOpts.SourceDateEpoch
+ ? *PreprocessorOpts.SourceDateEpoch
+ : std::time(nullptr);
+ getModule().addModuleFlag(llvm::Module::Max, "zos_translation_time",
+ static_cast<uint64_t>(TT));
+
+ // Multiple modes will be supported here.
+ getModule().addModuleFlag(llvm::Module::Error, "zos_le_char_mode",
+ llvm::MDString::get(VMContext, "ascii"));
+ }
+
llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
if ( Arch == llvm::Triple::arm
|| Arch == llvm::Triple::armeb
@@ -1067,6 +1121,15 @@ void CodeGenModule::Release() {
"sign-return-address-with-bkey", 1);
}
+ if (CodeGenOpts.StackClashProtector)
+ getModule().addModuleFlag(
+ llvm::Module::Override, "probe-stack",
+ llvm::MDString::get(TheModule.getContext(), "inline-asm"));
+
+ if (CodeGenOpts.StackProbeSize && CodeGenOpts.StackProbeSize != 4096)
+ getModule().addModuleFlag(llvm::Module::Min, "stack-probe-size",
+ CodeGenOpts.StackProbeSize);
+
if (!CodeGenOpts.MemoryProfileOutput.empty()) {
llvm::LLVMContext &Ctx = TheModule.getContext();
getModule().addModuleFlag(
@@ -1137,6 +1200,12 @@ void CodeGenModule::Release() {
if (CM != ~0u) {
llvm::CodeModel::Model codeModel = static_cast<llvm::CodeModel::Model>(CM);
getModule().setCodeModel(codeModel);
+
+ if (CM == llvm::CodeModel::Medium &&
+ Context.getTargetInfo().getTriple().getArch() ==
+ llvm::Triple::x86_64) {
+ getModule().setLargeDataThreshold(getCodeGenOpts().LargeDataThreshold);
+ }
}
}
@@ -1196,11 +1265,15 @@ void CodeGenModule::Release() {
getModule().setOverrideStackAlignment(getCodeGenOpts().StackAlignment);
if (getCodeGenOpts().SkipRaxSetup)
getModule().addModuleFlag(llvm::Module::Override, "SkipRaxSetup", 1);
+ if (getLangOpts().RegCall4)
+ getModule().addModuleFlag(llvm::Module::Override, "RegCallv4", 1);
if (getContext().getTargetInfo().getMaxTLSAlign())
getModule().addModuleFlag(llvm::Module::Error, "MaxTLSAlign",
getContext().getTargetInfo().getMaxTLSAlign());
+ getTargetCodeGenInfo().emitTargetGlobals(*this);
+
getTargetCodeGenInfo().emitTargetMetadata(*this, MangledDeclNames);
EmitBackendOptionsMetadata(getCodeGenOpts());
@@ -1371,9 +1444,24 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
}
if (!D)
return;
+
// Set visibility for definitions, and for declarations if requested globally
// or set explicitly.
LinkageInfo LV = D->getLinkageAndVisibility();
+
+ // OpenMP declare target variables must be visible to the host so they can
+ // be registered. We require protected visibility unless the variable has
+ // the DT_nohost modifier and does not need to be registered.
+ if (Context.getLangOpts().OpenMP &&
+ Context.getLangOpts().OpenMPIsTargetDevice && isa<VarDecl>(D) &&
+ D->hasAttr<OMPDeclareTargetDeclAttr>() &&
+ D->getAttr<OMPDeclareTargetDeclAttr>()->getDevType() !=
+ OMPDeclareTargetDeclAttr::DT_NoHost &&
+ LV.getVisibility() == HiddenVisibility) {
+ GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
+ return;
+ }
+
if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) {
// Reject incompatible dlllstorage and visibility annotations.
if (!LV.isVisibilityExplicit())
@@ -1407,6 +1495,7 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
return false;
const llvm::Triple &TT = CGM.getTriple();
+ const auto &CGOpts = CGM.getCodeGenOpts();
if (TT.isWindowsGNUEnvironment()) {
// In MinGW, variables without DLLImport can still be automatically
// imported from a DLL by the linker; don't mark variables that
@@ -1417,7 +1506,8 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
// such variables can't be marked as DSO local. (Native TLS variables
// can't be dllimported at all, though.)
if (GV->isDeclarationForLinker() && isa<llvm::GlobalVariable>(GV) &&
- (!GV->isThreadLocal() || CGM.getCodeGenOpts().EmulatedTLS))
+ (!GV->isThreadLocal() || CGM.getCodeGenOpts().EmulatedTLS) &&
+ CGOpts.AutoImport)
return false;
}
@@ -1440,7 +1530,6 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
return false;
// If this is not an executable, don't assume anything is local.
- const auto &CGOpts = CGM.getCodeGenOpts();
llvm::Reloc::Model RM = CGOpts.RelocationModel;
const auto &LOpts = CGM.getLangOpts();
if (RM != llvm::Reloc::Static && !LOpts.PIE) {
@@ -1626,7 +1715,7 @@ static void AppendTargetMangling(const CodeGenModule &CGM,
llvm::sort(Info.Features, [&Target](StringRef LHS, StringRef RHS) {
// Multiversioning doesn't allow "no-${feature}", so we can
// only have "+" prefixes here.
- assert(LHS.startswith("+") && RHS.startswith("+") &&
+ assert(LHS.starts_with("+") && RHS.starts_with("+") &&
"Features should always have a prefix.");
return Target.multiVersionSortPriority(LHS.substr(1)) >
Target.multiVersionSortPriority(RHS.substr(1));
@@ -1680,7 +1769,7 @@ static void AppendTargetClonesMangling(const CodeGenModule &CGM,
} else {
Out << '.';
StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
- if (FeatureStr.startswith("arch="))
+ if (FeatureStr.starts_with("arch="))
Out << "arch_" << FeatureStr.substr(sizeof("arch=") - 1);
else
Out << FeatureStr;
@@ -1707,7 +1796,10 @@ static std::string getMangledNameImpl(CodeGenModule &CGM, GlobalDecl GD,
if (FD &&
FD->getType()->castAs<FunctionType>()->getCallConv() == CC_X86RegCall) {
- Out << "__regcall3__" << II->getName();
+ if (CGM.getLangOpts().RegCall4)
+ Out << "__regcall4__" << II->getName();
+ else
+ Out << "__regcall3__" << II->getName();
} else if (FD && FD->hasAttr<CUDAGlobalAttr>() &&
GD.getKernelReferenceKind() == KernelReferenceKind::Stub) {
Out << "__device_stub__" << II->getName();
@@ -1936,9 +2028,9 @@ void CodeGenModule::EmitCtorList(CtorList &Fns, const char *GlobalName) {
for (const auto &I : Fns) {
auto ctor = ctors.beginStruct(CtorStructTy);
ctor.addInt(Int32Ty, I.Priority);
- ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
+ ctor.add(I.Initializer);
if (I.AssociatedData)
- ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData, VoidPtrTy));
+ ctor.add(I.AssociatedData);
else
ctor.addNullPointer(VoidPtrTy);
ctor.finishAndAddTo(ctors);
@@ -1965,15 +2057,6 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
if (const auto *Dtor = dyn_cast<CXXDestructorDecl>(D))
return getCXXABI().getCXXDestructorLinkage(Linkage, Dtor, GD.getDtorType());
- if (isa<CXXConstructorDecl>(D) &&
- cast<CXXConstructorDecl>(D)->isInheritingConstructor() &&
- Context.getTargetInfo().getCXXABI().isMicrosoft()) {
- // Our approach to inheriting constructors is fundamentally different from
- // that used by the MS ABI, so keep our inheriting constructor thunks
- // internal rather than trying to pick an unambiguous mangling for them.
- return llvm::GlobalValue::InternalLinkage;
- }
-
return getLLVMLinkageForDeclarator(D, Linkage);
}
@@ -1992,7 +2075,7 @@ llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) {
std::string OutName;
llvm::raw_string_ostream Out(OutName);
- getCXXABI().getMangleContext().mangleTypeName(
+ getCXXABI().getMangleContext().mangleCanonicalTypeName(
T, Out, getCodeGenOpts().SanitizeCfiICallNormalizeIntegers);
if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
@@ -2232,11 +2315,11 @@ static bool requiresMemberFunctionPointerTypeMetadata(CodeGenModule &CGM,
// Only functions whose address can be taken with a member function pointer
// need this sort of type metadata.
- return !MD->isStatic() && !MD->isVirtual() && !isa<CXXConstructorDecl>(MD) &&
- !isa<CXXDestructorDecl>(MD);
+ return MD->isImplicitObjectMemberFunction() && !MD->isVirtual() &&
+ !isa<CXXConstructorDecl, CXXDestructorDecl>(MD);
}
-std::vector<const CXXRecordDecl *>
+SmallVector<const CXXRecordDecl *, 0>
CodeGenModule::getMostBaseClasses(const CXXRecordDecl *RD) {
llvm::SetVector<const CXXRecordDecl *> MostBases;
@@ -2261,19 +2344,23 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
if (CodeGenOpts.StackClashProtector)
B.addAttribute("probe-stack", "inline-asm");
+ if (CodeGenOpts.StackProbeSize && CodeGenOpts.StackProbeSize != 4096)
+ B.addAttribute("stack-probe-size",
+ std::to_string(CodeGenOpts.StackProbeSize));
+
if (!hasUnwindExceptions(LangOpts))
B.addAttribute(llvm::Attribute::NoUnwind);
if (D && D->hasAttr<NoStackProtectorAttr>())
; // Do nothing.
else if (D && D->hasAttr<StrictGuardStackCheckAttr>() &&
- LangOpts.getStackProtector() == LangOptions::SSPOn)
+ isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn))
B.addAttribute(llvm::Attribute::StackProtectStrong);
- else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+ else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn))
B.addAttribute(llvm::Attribute::StackProtect);
- else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+ else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPStrong))
B.addAttribute(llvm::Attribute::StackProtectStrong);
- else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+ else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq))
B.addAttribute(llvm::Attribute::StackProtectReq);
if (!D) {
@@ -2288,6 +2375,14 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
return;
}
+ // Handle SME attributes that apply to function definitions,
+ // rather than to function prototypes.
+ if (D->hasAttr<ArmLocallyStreamingAttr>())
+ B.addAttribute("aarch64_pstate_sm_body");
+
+ if (D->hasAttr<ArmNewZAAttr>())
+ B.addAttribute("aarch64_pstate_za_new");
+
// Track whether we need to add the optnone LLVM attribute,
// starting with the default for this optimization level.
bool ShouldAddOptNone =
@@ -2893,6 +2988,9 @@ static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod,
}
void CodeGenModule::EmitModuleInitializers(clang::Module *Primary) {
+ assert(Primary->isNamedModuleUnit() &&
+ "We should only emit module initializers for named modules.");
+
// Emit the initializers in the order that sub-modules appear in the
// source, first Global Module Fragments, if present.
if (auto GMF = Primary->getGlobalModuleFragment()) {
@@ -2913,6 +3011,9 @@ void CodeGenModule::EmitModuleInitializers(clang::Module *Primary) {
// Third any associated with the Privat eMOdule Fragment, if present.
if (auto PMF = Primary->getPrivateModuleFragment()) {
for (Decl *D : getContext().getModuleInitializers(PMF)) {
+ // Skip import decls, the inits for those are called explicitly.
+ if (isa<ImportDecl>(D))
+ continue;
assert(isa<VarDecl>(D) && "PMF initializer decl is not a var?");
EmitTopLevelDecl(D);
}
@@ -3078,6 +3179,13 @@ void CodeGenModule::EmitVTablesOpportunistically() {
}
void CodeGenModule::EmitGlobalAnnotations() {
+ for (const auto& [MangledName, VD] : DeferredAnnotations) {
+ llvm::GlobalValue *GV = GetGlobalValue(MangledName);
+ if (GV)
+ AddGlobalAnnotations(VD, GV);
+ }
+ DeferredAnnotations.clear();
+
if (Annotations.empty())
return;
@@ -3150,10 +3258,9 @@ llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
".args");
GV->setSection(AnnotationSection);
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
- auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
- Lookup = Bitcasted;
- return Bitcasted;
+ Lookup = GV;
+ return GV;
}
llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
@@ -3169,17 +3276,14 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
if (GV->getAddressSpace() !=
getDataLayout().getDefaultGlobalsAddressSpace()) {
GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
- GV, GV->getValueType()->getPointerTo(
- getDataLayout().getDefaultGlobalsAddressSpace()));
+ GV,
+ llvm::PointerType::get(
+ GV->getContext(), getDataLayout().getDefaultGlobalsAddressSpace()));
}
// Create the ConstantStruct for the global annotation.
llvm::Constant *Fields[] = {
- llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
- llvm::ConstantExpr::getBitCast(AnnoGV, ConstGlobalsPtrTy),
- llvm::ConstantExpr::getBitCast(UnitGV, ConstGlobalsPtrTy),
- LineNoCst,
- Args,
+ GVInGlobalsAS, AnnoGV, UnitGV, LineNoCst, Args,
};
return llvm::ConstantStruct::getAnon(Fields);
}
@@ -3200,7 +3304,7 @@ bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
return true;
// NoSanitize by location. Check "mainfile" prefix.
auto &SM = Context.getSourceManager();
- const FileEntry &MainFile = *SM.getFileEntryForID(SM.getMainFileID());
+ FileEntryRef MainFile = *SM.getFileEntryRefForID(SM.getMainFileID());
if (NoSanitizeL.containsMainFile(Kind, MainFile.getName()))
return true;
@@ -3221,7 +3325,8 @@ bool CodeGenModule::isInNoSanitizeList(SanitizerMask Kind,
return true;
auto &SM = Context.getSourceManager();
if (NoSanitizeL.containsMainFile(
- Kind, SM.getFileEntryForID(SM.getMainFileID())->getName(), Category))
+ Kind, SM.getFileEntryRefForID(SM.getMainFileID())->getName(),
+ Category))
return true;
if (NoSanitizeL.containsLocation(Kind, Loc, Category))
return true;
@@ -3287,7 +3392,7 @@ CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
// If location is unknown, this may be a compiler-generated function. Assume
// it's located in the main file.
auto &SM = Context.getSourceManager();
- if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID()))
+ if (auto MainFile = SM.getFileEntryRefForID(SM.getMainFileID()))
if (auto V = ProfileList.isFileExcluded(MainFile->getName(), Kind))
return *V;
return ProfileList.getDefault(Kind);
@@ -3364,7 +3469,7 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) {
// codegen for global variables, because they may be marked as threadprivate.
if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS &&
getContext().getTargetInfo().isTLSSupported() && isa<VarDecl>(Global) &&
- !isTypeConstant(Global->getType(), false, false) &&
+ !Global->getType().isConstantStorage(getContext(), false, false) &&
!OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Global))
return false;
@@ -3419,9 +3524,7 @@ ConstantAddress CodeGenModule::GetAddrOfMSGuidDecl(const MSGuidDecl *GD) {
}
llvm::Type *Ty = getTypes().ConvertTypeForMem(GD->getType());
- llvm::Constant *Addr = llvm::ConstantExpr::getBitCast(
- GV, Ty->getPointerTo(GV->getAddressSpace()));
- return ConstantAddress(Addr, Ty, Alignment);
+ return ConstantAddress(GV, Ty, Alignment);
}
ConstantAddress CodeGenModule::GetAddrOfUnnamedGlobalConstantDecl(
@@ -3483,7 +3586,7 @@ ConstantAddress CodeGenModule::GetAddrOfTemplateParamObject(
GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
Emitter.finalize(GV);
- return ConstantAddress(GV, GV->getValueType(), Alignment);
+ return ConstantAddress(GV, GV->getValueType(), Alignment);
}
ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
@@ -3495,11 +3598,8 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
// See if there is already something with the target's name in the module.
llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee());
- if (Entry) {
- unsigned AS = getTypes().getTargetAddressSpace(VD->getType());
- auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
- return ConstantAddress(Ptr, DeclTy, Alignment);
- }
+ if (Entry)
+ return ConstantAddress(Entry, DeclTy, Alignment);
llvm::Constant *Aliasee;
if (isa<llvm::FunctionType>(DeclTy))
@@ -3517,6 +3617,14 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
return ConstantAddress(Aliasee, DeclTy, Alignment);
}
+template <typename AttrT> static bool hasImplicitAttr(const ValueDecl *D) {
+ if (!D)
+ return false;
+ if (auto *A = D->getAttr<AttrT>())
+ return A->isImplicit();
+ return D->isImplicit();
+}
+
void CodeGenModule::EmitGlobal(GlobalDecl GD) {
const auto *Global = cast<ValueDecl>(GD.getDecl());
@@ -3538,14 +3646,24 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
return emitCPUDispatchDefinition(GD);
// If this is CUDA, be selective about which declarations we emit.
+ // Non-constexpr non-lambda implicit host device functions are not emitted
+ // unless they are used on device side.
if (LangOpts.CUDA) {
if (LangOpts.CUDAIsDevice) {
- if (!Global->hasAttr<CUDADeviceAttr>() &&
+ const auto *FD = dyn_cast<FunctionDecl>(Global);
+ if ((!Global->hasAttr<CUDADeviceAttr>() ||
+ (LangOpts.OffloadImplicitHostDeviceTemplates && FD &&
+ hasImplicitAttr<CUDAHostAttr>(FD) &&
+ hasImplicitAttr<CUDADeviceAttr>(FD) && !FD->isConstexpr() &&
+ !isLambdaCallOperator(FD) &&
+ !getContext().CUDAImplicitHostDeviceFunUsedByDevice.count(FD))) &&
!Global->hasAttr<CUDAGlobalAttr>() &&
!Global->hasAttr<CUDAConstantAttr>() &&
!Global->hasAttr<CUDASharedAttr>() &&
!Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
- !Global->getType()->isCUDADeviceBuiltinTextureType())
+ !Global->getType()->isCUDADeviceBuiltinTextureType() &&
+ !(LangOpts.HIPStdPar && isa<FunctionDecl>(Global) &&
+ !Global->hasAttr<CUDAHostAttr>()))
return;
} else {
// We need to emit host-side 'shadows' for all global
@@ -3581,6 +3699,14 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
// Ignore declarations, they will be emitted on their first use.
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
+ // Update deferred annotations with the latest declaration if the function
+ // function was already used or defined.
+ if (FD->hasAttr<AnnotateAttr>()) {
+ StringRef MangledName = getMangledName(GD);
+ if (GetGlobalValue(MangledName))
+ DeferredAnnotations[MangledName] = FD;
+ }
+
// Forward declarations are emitted lazily on first use.
if (!FD->doesThisDeclarationHaveABody()) {
if (!FD->doesDeclarationForceExternallyVisibleDefinition())
@@ -3702,7 +3828,7 @@ namespace {
if (!BuiltinID || !BI.isLibFunction(BuiltinID))
return false;
StringRef BuiltinName = BI.getName(BuiltinID);
- if (BuiltinName.startswith("__builtin_") &&
+ if (BuiltinName.starts_with("__builtin_") &&
Name == BuiltinName.slice(strlen("__builtin_"), StringRef::npos)) {
return true;
}
@@ -3805,10 +3931,22 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) {
bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage)
return true;
+
const auto *F = cast<FunctionDecl>(GD.getDecl());
if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
return false;
+ // We don't import function bodies from other named module units since that
+ // behavior may break ABI compatibility of the current unit.
+ if (const Module *M = F->getOwningModule();
+ M && M->getTopLevelModule()->isNamedModule() &&
+ getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
+ !F->hasAttr<AlwaysInlineAttr>())
+ return false;
+
+ if (F->hasAttr<NoInlineAttr>())
+ return false;
+
if (F->hasAttr<DLLImportAttr>() && !F->hasAttr<AlwaysInlineAttr>()) {
// Check whether it would be safe to inline this dllimport function.
DLLImportFunctionVisitor Visitor;
@@ -3943,7 +4081,7 @@ TargetMVPriority(const TargetInfo &TI,
llvm::GlobalValue::LinkageTypes getMultiversionLinkage(CodeGenModule &CGM,
GlobalDecl GD) {
const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
- if (FD->getFormalLinkage() == InternalLinkage)
+ if (FD->getFormalLinkage() == Linkage::Internal)
return llvm::GlobalValue::InternalLinkage;
return llvm::GlobalValue::WeakODRLinkage;
}
@@ -4026,7 +4164,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
Feature.push_back(CurFeat.trim());
}
} else {
- if (Version.startswith("arch="))
+ if (Version.starts_with("arch="))
Architecture = Version.drop_front(sizeof("arch=") - 1);
else if (Version != "default")
Feature.push_back(Version);
@@ -4040,13 +4178,34 @@ void CodeGenModule::emitMultiVersionFunctions() {
}
llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
- if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant))
+ if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
ResolverConstant = IFunc->getResolver();
+ // In Aarch64, default versions of multiversioned functions are mangled to
+ // their 'normal' assembly name. This deviates from other targets which
+ // append a '.default' string. As a result we need to continue appending
+ // .ifunc in Aarch64.
+ // FIXME: Should Aarch64 mangling for 'default' multiversion function and
+ // in turn ifunc function match that of other targets?
+ if (FD->isTargetClonesMultiVersion() &&
+ !getTarget().getTriple().isAArch64()) {
+ const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
+ llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
+ std::string MangledName = getMangledNameImpl(
+ *this, GD, FD, /*OmitMultiVersionMangling=*/true);
+ // In prior versions of Clang, the mangling for ifuncs incorrectly
+ // included an .ifunc suffix. This alias is generated for backward
+ // compatibility. It is deprecated, and may be removed in the future.
+ auto *Alias = llvm::GlobalAlias::create(
+ DeclTy, 0, getMultiversionLinkage(*this, GD),
+ MangledName + ".ifunc", IFunc, &getModule());
+ SetCommonAttributes(FD, Alias);
+ }
+ }
llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
- if (supportsCOMDAT())
+ if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
ResolverFunc->setComdat(
getModule().getOrInsertComdat(ResolverFunc->getName()));
@@ -4155,8 +4314,9 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
// always run on at least a 'pentium'). We do this by deleting the 'least
// advanced' (read, lowest mangling letter).
while (Options.size() > 1 &&
- llvm::X86::getCpuSupportsMask(
- (Options.end() - 2)->Conditions.Features) == 0) {
+ llvm::all_of(llvm::X86::getCpuSupportsMask(
+ (Options.end() - 2)->Conditions.Features),
+ [](auto X) { return X == 0; })) {
StringRef LHSName = (Options.end() - 2)->Function->getName();
StringRef RHSName = (Options.end() - 1)->Function->getName();
if (LHSName.compare(RHSName) < 0)
@@ -4207,10 +4367,19 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
// Holds the name of the resolver, in ifunc mode this is the ifunc (which has
// a separate resolver).
std::string ResolverName = MangledName;
- if (getTarget().supportsIFunc())
- ResolverName += ".ifunc";
- else if (FD->isTargetMultiVersion())
+ if (getTarget().supportsIFunc()) {
+ // In Aarch64, default versions of multiversioned functions are mangled to
+ // their 'normal' assembly name. This deviates from other targets which
+ // append a '.default' string. As a result we need to continue appending
+ // .ifunc in Aarch64.
+ // FIXME: Should Aarch64 mangling for 'default' multiversion function and
+ // in turn ifunc function match that of other targets?
+ if (!FD->isTargetClonesMultiVersion() ||
+ getTarget().getTriple().isAArch64())
+ ResolverName += ".ifunc";
+ } else if (FD->isTargetMultiVersion()) {
ResolverName += ".resolver";
+ }
// If the resolver has already been created, just return it.
if (llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName))
@@ -4332,8 +4501,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
// (If function is requested for a definition, we always need to create a new
// function, not just return a bitcast.)
if (!IsForDefinition)
- return llvm::ConstantExpr::getBitCast(
- Entry, Ty->getPointerTo(Entry->getAddressSpace()));
+ return Entry;
}
// This function doesn't have a complete type (for example, the return
@@ -4353,6 +4521,11 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
Entry ? StringRef() : MangledName, &getModule());
+ // Store the declaration associated with this function so it is potentially
+ // updated by further declarations or definitions and emitted at the end.
+ if (D && D->hasAttr<AnnotateAttr>())
+ DeferredAnnotations[MangledName] = cast<ValueDecl>(D);
+
// If we already created a function with the same mangled name (but different
// type) before, take its name and add it to the list of functions to be
// replaced with F at the end of CodeGen.
@@ -4373,9 +4546,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
Entry->removeDeadConstantUsers();
}
- llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
- F, Entry->getValueType()->getPointerTo(Entry->getAddressSpace()));
- addGlobalValReplacement(Entry, BC);
+ addGlobalValReplacement(Entry, F);
}
assert(F->getName() == MangledName && "name was uniqued!");
@@ -4437,8 +4608,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
return F;
}
- return llvm::ConstantExpr::getBitCast(F,
- Ty->getPointerTo(F->getAddressSpace()));
+ return F;
}
/// GetAddrOfFunction - Return the address of the given function. If Ty is
@@ -4475,7 +4645,7 @@ CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty, bool ForVTable,
cast<llvm::Function>(F->stripPointerCasts()), GD);
if (IsForDefinition)
return F;
- return llvm::ConstantExpr::getBitCast(Handle, Ty->getPointerTo());
+ return Handle;
}
return F;
}
@@ -4484,9 +4654,7 @@ llvm::Constant *CodeGenModule::GetFunctionStart(const ValueDecl *Decl) {
llvm::GlobalValue *F =
cast<llvm::GlobalValue>(GetAddrOfFunction(Decl)->stripPointerCasts());
- return llvm::ConstantExpr::getBitCast(
- llvm::NoCFIValue::get(F),
- llvm::Type::getInt8PtrTy(VMContext, F->getAddressSpace()));
+ return llvm::NoCFIValue::get(F);
}
static const FunctionDecl *
@@ -4567,27 +4735,6 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType *FTy, StringRef Name,
return {FTy, C};
}
-/// isTypeConstant - Determine whether an object of this type can be emitted
-/// as a constant.
-///
-/// If ExcludeCtor is true, the duration when the object's constructor runs
-/// will not be considered. The caller will need to verify that the object is
-/// not written to during its construction. ExcludeDtor works similarly.
-bool CodeGenModule::isTypeConstant(QualType Ty, bool ExcludeCtor,
- bool ExcludeDtor) {
- if (!Ty.isConstant(Context) && !Ty->isReferenceType())
- return false;
-
- if (Context.getLangOpts().CPlusPlus) {
- if (const CXXRecordDecl *Record
- = Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
- return ExcludeCtor && !Record->hasMutableFields() &&
- (Record->hasTrivialDestructor() || ExcludeDtor);
- }
-
- return true;
-}
-
/// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
/// create and return an llvm GlobalVariable with the specified type and address
/// space. If there is something in the module with the specified name, return
@@ -4644,15 +4791,14 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
}
// Make sure the result is of the correct type.
- if (Entry->getType()->getAddressSpace() != TargetAS) {
- return llvm::ConstantExpr::getAddrSpaceCast(Entry,
- Ty->getPointerTo(TargetAS));
- }
+ if (Entry->getType()->getAddressSpace() != TargetAS)
+ return llvm::ConstantExpr::getAddrSpaceCast(
+ Entry, llvm::PointerType::get(Ty->getContext(), TargetAS));
// (If global is requested for a definition, we always need to create a new
// global, not just return a bitcast.)
if (!IsForDefinition)
- return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo(TargetAS));
+ return Entry;
}
auto DAddrSpace = GetGlobalVarAddressSpace(D);
@@ -4668,9 +4814,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
GV->takeName(Entry);
if (!Entry->use_empty()) {
- llvm::Constant *NewPtrForOldDecl =
- llvm::ConstantExpr::getBitCast(GV, Entry->getType());
- Entry->replaceAllUsesWith(NewPtrForOldDecl);
+ Entry->replaceAllUsesWith(GV);
}
Entry->eraseFromParent();
@@ -4694,7 +4838,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
// FIXME: This code is overly simple and should be merged with other global
// handling.
- GV->setConstant(isTypeConstant(D->getType(), false, false));
+ GV->setConstant(D->getType().isConstantStorage(getContext(), false, false));
GV->setAlignment(getContext().getDeclAlign(D).getAsAlign());
@@ -4790,7 +4934,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
assert(getContext().getTargetAddressSpace(ExpectedAS) == TargetAS);
if (DAddrSpace != ExpectedAS) {
return getTargetCodeGenInfo().performAddrSpaceCast(
- *this, GV, DAddrSpace, ExpectedAS, Ty->getPointerTo(TargetAS));
+ *this, GV, DAddrSpace, ExpectedAS,
+ llvm::PointerType::get(getLLVMContext(), TargetAS));
}
return GV;
@@ -4848,9 +4993,7 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable(
GV->takeName(OldGV);
if (!OldGV->use_empty()) {
- llvm::Constant *NewPtrForOldDecl =
- llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
- OldGV->replaceAllUsesWith(NewPtrForOldDecl);
+ OldGV->replaceAllUsesWith(GV);
}
OldGV->eraseFromParent();
@@ -5002,7 +5145,8 @@ castStringLiteralToDefaultAddressSpace(CodeGenModule &CGM,
if (AS != LangAS::Default)
Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
CGM, GV, AS, LangAS::Default,
- GV->getValueType()->getPointerTo(
+ llvm::PointerType::get(
+ CGM.getLLVMContext(),
CGM.getContext().getTargetAddressSpace(LangAS::Default)));
}
return Cast;
@@ -5020,7 +5164,7 @@ void CodeGenModule::MaybeHandleStaticInExternC(const SomeDecl *D,
return;
// Must have internal linkage and an ordinary name.
- if (!D->getIdentifier() || D->getFormalLinkage() != InternalLinkage)
+ if (!D->getIdentifier() || D->getFormalLinkage() != Linkage::Internal)
return;
// Must be in an extern "C" context. Entities declared directly within
@@ -5254,7 +5398,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
// If it is safe to mark the global 'constant', do so now.
GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
- isTypeConstant(D->getType(), true, true));
+ D->getType().isConstantStorage(getContext(), true, true));
// If it is in a read-only section, mark it 'constant'.
if (const SectionAttr *SA = D->getAttr<SectionAttr>()) {
@@ -5668,8 +5812,8 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
AddGlobalCtor(Fn, CA->getPriority());
if (const DestructorAttr *DA = D->getAttr<DestructorAttr>())
AddGlobalDtor(Fn, DA->getPriority(), true);
- if (D->hasAttr<AnnotateAttr>())
- AddGlobalAnnotations(D, Fn);
+ if (getLangOpts().OpenMP && D->hasAttr<OMPDeclareTargetDeclAttr>())
+ getOpenMPRuntime().emitDeclareTargetFunction(D, GV);
}
void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
@@ -5733,8 +5877,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
// Remove it and replace uses of it with the alias.
GA->takeName(Entry);
- Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
- Entry->getType()));
+ Entry->replaceAllUsesWith(GA);
Entry->eraseFromParent();
} else {
GA->setName(MangledName);
@@ -5812,12 +5955,13 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
// Remove it and replace uses of it with the ifunc.
GIF->takeName(Entry);
- Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GIF,
- Entry->getType()));
+ Entry->replaceAllUsesWith(GIF);
Entry->eraseFromParent();
} else
GIF->setName(MangledName);
-
+ if (auto *F = dyn_cast<llvm::Function>(Resolver)) {
+ F->addFnAttr(llvm::Attribute::DisableSanitizerInstrumentation);
+ }
SetCommonAttributes(GD, GIF);
}
@@ -5981,7 +6125,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
}
// Note: -fwritable-strings doesn't make the backing store strings of
- // CFStrings writable. (See <rdar://problem/10657500>)
+ // CFStrings writable.
auto *GV =
new llvm::GlobalVariable(getModule(), C->getType(), /*isConstant=*/true,
llvm::GlobalValue::PrivateLinkage, C, ".str");
@@ -6007,9 +6151,6 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
llvm::Constant *Str =
llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
- if (isUTF16)
- // Cast the UTF16 string to the correct type.
- Str = llvm::ConstantExpr::getBitCast(Str, Int8PtrTy);
Fields.add(Str);
// String length.
@@ -6067,12 +6208,10 @@ QualType CodeGenModule::getObjCFastEnumerationStateType() {
D->startDefinition();
QualType FieldTypes[] = {
- Context.UnsignedLongTy,
- Context.getPointerType(Context.getObjCIdType()),
- Context.getPointerType(Context.UnsignedLongTy),
- Context.getConstantArrayType(Context.UnsignedLongTy,
- llvm::APInt(32, 5), nullptr, ArrayType::Normal, 0)
- };
+ Context.UnsignedLongTy, Context.getPointerType(Context.getObjCIdType()),
+ Context.getPointerType(Context.UnsignedLongTy),
+ Context.getConstantArrayType(Context.UnsignedLongTy, llvm::APInt(32, 5),
+ nullptr, ArraySizeModifier::Normal, 0)};
for (size_t i = 0; i < 4; ++i) {
FieldDecl *Field = FieldDecl::Create(Context,
@@ -6300,7 +6439,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
VD, E->getManglingNumber(), Out);
APValue *Value = nullptr;
- if (E->getStorageDuration() == SD_Static && VD && VD->evaluateValue()) {
+ if (E->getStorageDuration() == SD_Static && VD->evaluateValue()) {
// If the initializer of the extending declaration is a constant
// initializer, we should have a cached constant initializer for this
// temporary. Note that this might have a different value from the value
@@ -6315,8 +6454,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
!EvalResult.hasSideEffects())
Value = &EvalResult.Val;
- LangAS AddrSpace =
- VD ? GetGlobalVarAddressSpace(VD) : MaterializedType.getAddressSpace();
+ LangAS AddrSpace = GetGlobalVarAddressSpace(VD);
std::optional<ConstantEmitter> emitter;
llvm::Constant *InitialValue = nullptr;
@@ -6327,8 +6465,9 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
emitter.emplace(*this);
InitialValue = emitter->emitForInitializer(*Value, AddrSpace,
MaterializedType);
- Constant = isTypeConstant(MaterializedType, /*ExcludeCtor*/ Value,
- /*ExcludeDtor*/ false);
+ Constant =
+ MaterializedType.isConstantStorage(getContext(), /*ExcludeCtor*/ Value,
+ /*ExcludeDtor*/ false);
Type = InitialValue->getType();
} else {
// No initializer, the initialization will be provided when we
@@ -6372,15 +6511,15 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
if (AddrSpace != LangAS::Default)
CV = getTargetCodeGenInfo().performAddrSpaceCast(
*this, GV, AddrSpace, LangAS::Default,
- Type->getPointerTo(
+ llvm::PointerType::get(
+ getLLVMContext(),
getContext().getTargetAddressSpace(LangAS::Default)));
// Update the map with the new temporary. If we created a placeholder above,
// replace it with the new global now.
llvm::Constant *&Entry = MaterializedGlobalTemporaryMap[E];
if (Entry) {
- Entry->replaceAllUsesWith(
- llvm::ConstantExpr::getBitCast(CV, Entry->getType()));
+ Entry->replaceAllUsesWith(CV);
llvm::cast<llvm::GlobalVariable>(Entry)->eraseFromParent();
}
Entry = CV;
@@ -6450,7 +6589,7 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
/*isInstance=*/true, /*isVariadic=*/false,
/*isPropertyAccessor=*/true, /*isSynthesizedAccessorStub=*/false,
/*isImplicitlyDeclared=*/true,
- /*isDefined=*/false, ObjCMethodDecl::Required);
+ /*isDefined=*/false, ObjCImplementationControl::Required);
D->addInstanceMethod(DTORMethod);
CodeGenFunction(*this).GenerateObjCCtorDtorMethod(D, DTORMethod, false);
D->setHasDestructors(true);
@@ -6471,7 +6610,7 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
/*isVariadic=*/false,
/*isPropertyAccessor=*/true, /*isSynthesizedAccessorStub=*/false,
/*isImplicitlyDeclared=*/true,
- /*isDefined=*/false, ObjCMethodDecl::Required);
+ /*isDefined=*/false, ObjCImplementationControl::Required);
D->addInstanceMethod(CTORMethod);
CodeGenFunction(*this).GenerateObjCCtorDtorMethod(D, CTORMethod, true);
D->setHasNonZeroConstructors(true);
@@ -6479,8 +6618,8 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) {
// EmitLinkageSpec - Emit all declarations in a linkage spec.
void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) {
- if (LSD->getLanguage() != LinkageSpecDecl::lang_c &&
- LSD->getLanguage() != LinkageSpecDecl::lang_cxx) {
+ if (LSD->getLanguage() != LinkageSpecLanguageIDs::C &&
+ LSD->getLanguage() != LinkageSpecLanguageIDs::CXX) {
ErrorUnsupported(LSD, "linkage spec");
return;
}
@@ -6860,9 +6999,7 @@ void CodeGenModule::AddDeferredUnusedCoverageMapping(Decl *D) {
SourceManager &SM = getContext().getSourceManager();
if (LimitedCoverage && SM.getMainFileID() != SM.getFileID(D->getBeginLoc()))
break;
- auto I = DeferredEmptyCoverageMappingDecls.find(D);
- if (I == DeferredEmptyCoverageMappingDecls.end())
- DeferredEmptyCoverageMappingDecls[D] = true;
+ DeferredEmptyCoverageMappingDecls.try_emplace(D, true);
break;
}
default:
@@ -6878,11 +7015,7 @@ void CodeGenModule::ClearUnusedCoverageMapping(const Decl *D) {
if (Fn->isTemplateInstantiation())
ClearUnusedCoverageMapping(Fn->getTemplateInstantiationPattern());
}
- auto I = DeferredEmptyCoverageMappingDecls.find(D);
- if (I == DeferredEmptyCoverageMappingDecls.end())
- DeferredEmptyCoverageMappingDecls[D] = false;
- else
- I->second = false;
+ DeferredEmptyCoverageMappingDecls.insert_or_assign(D, false);
}
void CodeGenModule::EmitDeferredUnusedCoverageMappings() {
@@ -7198,7 +7331,7 @@ CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
if (isExternallyVisible(T->getLinkage())) {
std::string OutName;
llvm::raw_string_ostream Out(OutName);
- getCXXABI().getMangleContext().mangleTypeName(
+ getCXXABI().getMangleContext().mangleCanonicalTypeName(
T, Out, getCodeGenOpts().SanitizeCfiICallNormalizeIntegers);
if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers)
@@ -7432,7 +7565,7 @@ void CodeGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
// Get the UniqueID for the file containing the decl.
llvm::sys::fs::UniqueID ID;
- if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
+ if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) {
PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false);
assert(PLoc.isValid() && "Source location is expected to be valid.");
if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
@@ -7452,6 +7585,8 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
assert(NewBuilder->DeferredDecls.empty() &&
"Newly created module should not have deferred decls");
NewBuilder->DeferredDecls = std::move(DeferredDecls);
+ assert(EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
assert(NewBuilder->DeferredVTables.empty() &&
"Newly created module should not have deferred vtables");
@@ -7467,10 +7602,5 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
NewBuilder->TBAA = std::move(TBAA);
- assert(NewBuilder->EmittedDeferredDecls.empty() &&
- "Still have (unmerged) EmittedDeferredDecls deferred decls");
-
- NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
-
NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
}