Skip to content

Commit 7e61a41

Browse files
committed
changes from last revision:
* changed the condition for early exit * assert that the first lookup returned null if you are at the fallthrough
1 parent aff962d commit 7e61a41

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,15 +4554,17 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
45544554
ResolverName += ".resolver";
45554555
}
45564556

4557+
bool ShouldReturnIFunc =
4558+
getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion();
4559+
45574560
// If the resolver has already been created, just return it. This lookup may
45584561
// yield a function declaration instead of a resolver on AArch64. That is
45594562
// because we didn't know whether a resolver will be generated when we first
45604563
// encountered a use of the symbol named after this resolver. Therefore,
45614564
// targets which support ifuncs should not return here unless we actually
45624565
// found an ifunc.
45634566
llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName);
4564-
if (ResolverGV &&
4565-
(isa<llvm::GlobalIFunc>(ResolverGV) || !getTarget().supportsIFunc()))
4567+
if (ResolverGV && (isa<llvm::GlobalIFunc>(ResolverGV) || !ShouldReturnIFunc))
45664568
return ResolverGV;
45674569

45684570
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
@@ -4575,7 +4577,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
45754577

45764578
// For cpu_specific, don't create an ifunc yet because we don't know if the
45774579
// cpu_dispatch will be emitted in this translation unit.
4578-
if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
4580+
if (ShouldReturnIFunc) {
45794581
unsigned AS = getTypes().getTargetAddressSpace(FD->getType());
45804582
llvm::Type *ResolverType =
45814583
llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false);
@@ -4594,7 +4596,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
45944596

45954597
llvm::Constant *Resolver = GetOrCreateLLVMFunction(
45964598
ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false);
4597-
assert(isa<llvm::GlobalValue>(Resolver) &&
4599+
assert(isa<llvm::GlobalValue>(Resolver) && !ResolverGV &&
45984600
"Resolver should be created for the first time");
45994601
SetCommonAttributes(FD, cast<llvm::GlobalValue>(Resolver));
46004602
return Resolver;

0 commit comments

Comments
 (0)