diff options
author | Alexandros Lamprineas <alexandros.lamprineas@arm.com> | 2024-11-26 07:45:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 07:45:15 +0000 |
commit | 56eb559b1d49ec6fa2d75753078e5b57f4b606c2 (patch) | |
tree | 7416a82cc434e6c259ece4c3e2cc9b11b2927a6c /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 5e3f6150b1d490090faf945777985b18db73ea3f (diff) | |
download | llvm-56eb559b1d49ec6fa2d75753078e5b57f4b606c2.zip llvm-56eb559b1d49ec6fa2d75753078e5b57f4b606c2.tar.gz llvm-56eb559b1d49ec6fa2d75753078e5b57f4b606c2.tar.bz2 |
[clang][FMV] Fix crash with cpu_specific attribute. (#115762)
When dealing with cpu_specific GlobalDecl,
GetOrCreateMultiVersionResolver should immediately return the already
created llvm function if it exists.
Fixes https://github.com/llvm/llvm-project/issues/115299.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 1ff95ed..716c434 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4562,6 +4562,9 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) { ResolverName += ".resolver"; } + bool ShouldReturnIFunc = + getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion(); + // If the resolver has already been created, just return it. This lookup may // yield a function declaration instead of a resolver on AArch64. That is // because we didn't know whether a resolver will be generated when we first @@ -4569,8 +4572,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) { // targets which support ifuncs should not return here unless we actually // found an ifunc. llvm::GlobalValue *ResolverGV = GetGlobalValue(ResolverName); - if (ResolverGV && - (isa<llvm::GlobalIFunc>(ResolverGV) || !getTarget().supportsIFunc())) + if (ResolverGV && (isa<llvm::GlobalIFunc>(ResolverGV) || !ShouldReturnIFunc)) return ResolverGV; const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD); @@ -4583,7 +4585,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) { // For cpu_specific, don't create an ifunc yet because we don't know if the // cpu_dispatch will be emitted in this translation unit. - if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) { + if (ShouldReturnIFunc) { unsigned AS = getTypes().getTargetAddressSpace(FD->getType()); llvm::Type *ResolverType = llvm::FunctionType::get(llvm::PointerType::get(DeclTy, AS), false); @@ -4602,11 +4604,9 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) { llvm::Constant *Resolver = GetOrCreateLLVMFunction( ResolverName, DeclTy, GlobalDecl{}, /*ForVTable=*/false); - assert(isa<llvm::GlobalValue>(Resolver) && + assert(isa<llvm::GlobalValue>(Resolver) && !ResolverGV && "Resolver should be created for the first time"); SetCommonAttributes(FD, cast<llvm::GlobalValue>(Resolver)); - if (ResolverGV) - replaceDeclarationWith(ResolverGV, Resolver); return Resolver; } |