================
@@ -4652,6 +4659,7 @@ llvm::Constant
*CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
"", Resolver, &getModule());
GIF->setName(ResolverName);
SetCommonAttributes(FD, GIF);
+ SetResolverAttrs(cast<llvm::Function>(Resolver));
----------------
atrosinenko wrote:
Considering calling either `SetCommonAttributes` or `setGVProperties`, here are
the attributes which could be set with some reasonable value of `GD` (as I'm
not sure if it would be correct to pass through the `GD` object corresponding
to the function defined in the source code when setting attributes of a
synthetic resolver function).
[`SetCommonAttributes`](https://github.com/llvm/llvm-project/blob/1dbe65a008ea7731bf91910ddeb13f53758db5c2/clang/lib/CodeGen/CodeGenModule.cpp#L2845):
Checking for `UsedAttr` doesn't make much sense in our case, neither we deal
with a variable declaration, thus the only relevant fragment is
```cpp
const Decl *D = GD.getDecl();
if (isa_and_nonnull<NamedDecl>(D))
setGVProperties(GV, GD);
else
GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
```
[`setGVProperties(llvm::GlobalValue *,
GlobalDecl)`](https://github.com/llvm/llvm-project/blob/1dbe65a008ea7731bf91910ddeb13f53758db5c2/clang/lib/CodeGen/CodeGenModule.cpp#L1925)
first calls `setDLLImportDLLExport` (irrelevant, as it handles
externally-visible declaration) and then `setGVPropertiesAux`:
```cpp
void CodeGenModule::setGVPropertiesAux(llvm::GlobalValue *GV,
const NamedDecl *D) const {
setGlobalVisibility(GV, D);
setDSOLocal(GV);
GV->setPartition(CodeGenOpts.SymbolPartition);
}
```
The only its callee which uses the `NamedDecl *D` argument is
[`setGlobalVisibility(llvm::GlobalValue *, const NamedDecl
*)`](https://github.com/llvm/llvm-project/blob/1dbe65a008ea7731bf91910ddeb13f53758db5c2/clang/lib/CodeGen/CodeGenModule.cpp#L1744)
function that calls `GV->setVisibility(...)` with the correct visibility type.
Notably, if `GV` has local linkage, it is always `DefaultVisibility` and `D` is
not even checked.
Considering the `EmitMultiVersionResolver`, it can be called from two places:
either
[`emitCPUDispatchDefinition`](https://github.com/llvm/llvm-project/blob/1dbe65a008ea7731bf91910ddeb13f53758db5c2/clang/lib/CodeGen/CodeGenModule.cpp#L4626)
or
[`emitMultiVersionFunctions`](https://github.com/llvm/llvm-project/blob/1dbe65a008ea7731bf91910ddeb13f53758db5c2/clang/lib/CodeGen/CodeGenModule.cpp#L4495),
and in both cases the resolver's linkage is explicitly computed to be either
`WeakODRLinkage` or `InternalLinkage` (see
e3b10525b489b604d6a1e540be78bda80afb5868).
A proof of concept pushed in 33a92e00d7acf0041a7d1579cf7a7d3bc64386d4
https://github.com/llvm/llvm-project/pull/141573
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits