aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0ebab14..0b660e3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4610,12 +4610,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
}
llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
- ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
-
- if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
- ResolverFunc->setComdat(
- getModule().getOrInsertComdat(ResolverFunc->getName()));
-
const TargetInfo &TI = getTarget();
llvm::stable_sort(
Options, [&TI](const CodeGenFunction::FMVResolverOption &LHS,
@@ -4624,6 +4618,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
});
CodeGenFunction CGF(*this);
CGF.EmitMultiVersionResolver(ResolverFunc, Options);
+
+ setMultiVersionResolverAttributes(ResolverFunc, GD);
+ if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
+ ResolverFunc->setComdat(
+ getModule().getOrInsertComdat(ResolverFunc->getName()));
}
// Ensure that any additions to the deferred decls list caused by emitting a
@@ -4674,7 +4673,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
auto *ResolverFunc = cast<llvm::Function>(GetOrCreateLLVMFunction(
ResolverName, ResolverType, ResolverGD, /*ForVTable=*/false));
- ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
+
if (supportsCOMDAT())
ResolverFunc->setComdat(
getModule().getOrInsertComdat(ResolverFunc->getName()));
@@ -4740,6 +4739,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
CodeGenFunction CGF(*this);
CGF.EmitMultiVersionResolver(ResolverFunc, Options);
+ setMultiVersionResolverAttributes(ResolverFunc, GD);
if (getTarget().supportsIFunc()) {
llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage(*this, GD);
@@ -4858,6 +4858,26 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
return Resolver;
}
+void CodeGenModule::setMultiVersionResolverAttributes(llvm::Function *Resolver,
+ GlobalDecl GD) {
+ const NamedDecl *D = dyn_cast_or_null<NamedDecl>(GD.getDecl());
+ Resolver->setLinkage(getMultiversionLinkage(*this, GD));
+
+ // Function body has to be emitted before calling setGlobalVisibility
+ // for Resolver to be considered as definition.
+ setGlobalVisibility(Resolver, D);
+
+ setDSOLocal(Resolver);
+
+ // Set the default target-specific attributes, such as PAC and BTI ones on
+ // AArch64. Not passing Decl to prevent setting unrelated attributes,
+ // as Resolver can be shared by multiple declarations.
+ // FIXME Some targets may require a non-null D to set some attributes
+ // (such as "stackrealign" on X86, even when it is requested via
+ // "-mstackrealign" command line option).
+ getTargetCodeGenInfo().setTargetAttributes(/*D=*/nullptr, Resolver, *this);
+}
+
bool CodeGenModule::shouldDropDLLAttribute(const Decl *D,
const llvm::GlobalValue *GV) const {
auto SC = GV->getDLLStorageClass();