Skip to content

Commit 95cea7d

Browse files
Merge pull request #25095 from aschwaighofer/irgen_fix_getlocalselfmetadata-5.1
[5.1] IRGen: Fix getLocalSelfMetadata
2 parents 7c33f22 + 3d5ed74 commit 95cea7d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,11 @@ llvm::Value *IRGenFunction::getLocalSelfMetadata() {
17031703
// with the correct value.
17041704

17051705
llvm::IRBuilderBase::InsertPointGuard guard(Builder);
1706-
Builder.SetInsertPoint(&CurFn->getEntryBlock(),
1707-
CurFn->getEntryBlock().begin());
1706+
auto insertPt = isa<llvm::Instruction>(LocalSelf)
1707+
? std::next(llvm::BasicBlock::iterator(
1708+
cast<llvm::Instruction>(LocalSelf)))
1709+
: CurFn->getEntryBlock().begin();
1710+
Builder.SetInsertPoint(&CurFn->getEntryBlock(), insertPt);
17081711

17091712
switch (SelfKind) {
17101713
case SwiftMetatype:

test/IRGen/objc_generic_class_metadata.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,18 @@ bb0(%0 : $@objc_metatype K<P>.Type):
112112
%3 = apply %2<P>() : $@convention(thin) <τ_0_0 > () -> ()
113113
return undef : $()
114114
}
115+
116+
public class D {
117+
}
118+
119+
// CHECK: define void @testDynamicSelfMetatype(i8*, i8*)
120+
// CHECK: [[C:%.*]] = bitcast i8* %0 to %T27objc_generic_class_metadata1DC*
121+
// CHECK: [[O:%.*]] = bitcast %T27objc_generic_class_metadata1DC* [[C]] to %objc_object*
122+
// CHECK: call %swift.type* @swift_getObjectType(%objc_object* [[O]]
123+
sil @testDynamicSelfMetatype : $@convention(objc_method) (@owned D) -> () {
124+
bb0(%0 : $D):
125+
%1 = metatype $@thick @dynamic_self D.Type
126+
return undef : $()
127+
}
128+
129+
sil_vtable D {}

0 commit comments

Comments
 (0)