GlobalIFunc: Make ifunc respect function address spaces

This commit is contained in:
Matt Arsenault 2022-11-22 21:02:20 -05:00
parent 6463961941
commit 0d527e56a5
3 changed files with 36 additions and 3 deletions

View File

@ -2873,8 +2873,8 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
Type *ResolverFTy =
GlobalIFunc::getResolverFunctionType(GI->getValueType());
// Transparently fix up the type for compatibility with older bitcode
GI->setResolver(
ConstantExpr::getBitCast(C, ResolverFTy->getPointerTo()));
GI->setResolver(ConstantExpr::getBitCast(
C, ResolverFTy->getPointerTo(GI->getAddressSpace())));
} else {
return error("Expected an alias or an ifunc");
}

View File

@ -889,7 +889,7 @@ void Verifier::visitGlobalIFunc(const GlobalIFunc &GI) {
const Type *ResolverTy = GI.getResolver()->getType();
const Type *ResolverFuncTy =
GlobalIFunc::getResolverFunctionType(GI.getValueType());
Check(ResolverTy == ResolverFuncTy->getPointerTo(),
Check(ResolverTy == ResolverFuncTy->getPointerTo(GI.getAddressSpace()),
"IFunc resolver has incorrect type", &GI);
}

View File

@ -0,0 +1,33 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
target datalayout = "P1"
; CHECK: @ifunc_as0 = ifunc void (), ptr @resolver_as0
@ifunc_as0 = ifunc void (), ptr @resolver_as0
; CHECK: @ifunc_as1 = ifunc void (), ptr addrspace(1) @resolver_as1
@ifunc_as1 = ifunc void (), ptr addrspace(1) @resolver_as1
; CHECK: define ptr @resolver_as0() addrspace(0) {
define ptr @resolver_as0() addrspace(0) {
ret ptr null
}
; CHECK: define ptr @resolver_as1() addrspace(1) {
define ptr @resolver_as1() addrspace(1) {
ret ptr null
}
; CHECK: define void @call_ifunc_as0() addrspace(1) {
; CHECK-NEXT: call addrspace(0) void @ifunc_as0()
define void @call_ifunc_as0() addrspace(1) {
call addrspace(0) void @ifunc_as0()
ret void
}
; CHECK: define void @call_ifunc_as1() addrspace(1) {
; CHECK-NEXT: call addrspace(1) void @ifunc_as1()
define void @call_ifunc_as1() addrspace(1) {
call addrspace(1) void @ifunc_as1()
ret void
}