Skip to content

Commit 0d527e5

Browse files
committed
GlobalIFunc: Make ifunc respect function address spaces
1 parent 6463961 commit 0d527e5

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,8 +2873,8 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
28732873
Type *ResolverFTy =
28742874
GlobalIFunc::getResolverFunctionType(GI->getValueType());
28752875
// Transparently fix up the type for compatibility with older bitcode
2876-
GI->setResolver(
2877-
ConstantExpr::getBitCast(C, ResolverFTy->getPointerTo()));
2876+
GI->setResolver(ConstantExpr::getBitCast(
2877+
C, ResolverFTy->getPointerTo(GI->getAddressSpace())));
28782878
} else {
28792879
return error("Expected an alias or an ifunc");
28802880
}

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ void Verifier::visitGlobalIFunc(const GlobalIFunc &GI) {
889889
const Type *ResolverTy = GI.getResolver()->getType();
890890
const Type *ResolverFuncTy =
891891
GlobalIFunc::getResolverFunctionType(GI.getValueType());
892-
Check(ResolverTy == ResolverFuncTy->getPointerTo(),
892+
Check(ResolverTy == ResolverFuncTy->getPointerTo(GI.getAddressSpace()),
893893
"IFunc resolver has incorrect type", &GI);
894894
}
895895

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
2+
3+
target datalayout = "P1"
4+
5+
; CHECK: @ifunc_as0 = ifunc void (), ptr @resolver_as0
6+
@ifunc_as0 = ifunc void (), ptr @resolver_as0
7+
8+
; CHECK: @ifunc_as1 = ifunc void (), ptr addrspace(1) @resolver_as1
9+
@ifunc_as1 = ifunc void (), ptr addrspace(1) @resolver_as1
10+
11+
; CHECK: define ptr @resolver_as0() addrspace(0) {
12+
define ptr @resolver_as0() addrspace(0) {
13+
ret ptr null
14+
}
15+
16+
; CHECK: define ptr @resolver_as1() addrspace(1) {
17+
define ptr @resolver_as1() addrspace(1) {
18+
ret ptr null
19+
}
20+
21+
; CHECK: define void @call_ifunc_as0() addrspace(1) {
22+
; CHECK-NEXT: call addrspace(0) void @ifunc_as0()
23+
define void @call_ifunc_as0() addrspace(1) {
24+
call addrspace(0) void @ifunc_as0()
25+
ret void
26+
}
27+
28+
; CHECK: define void @call_ifunc_as1() addrspace(1) {
29+
; CHECK-NEXT: call addrspace(1) void @ifunc_as1()
30+
define void @call_ifunc_as1() addrspace(1) {
31+
call addrspace(1) void @ifunc_as1()
32+
ret void
33+
}

0 commit comments

Comments
 (0)