Skip to content

Commit 0be4aff

Browse files
committed
Sema: Assigning vars of generic param type should not use runtime metadata.
1 parent 611c6be commit 0be4aff

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ class FindCapturedVars : public ASTWalker {
397397
// doesn't require its type metadata.
398398
if (auto declRef = dyn_cast<DeclRefExpr>(E))
399399
return (!declRef->getDecl()->isObjC()
400-
&& !E->getType()->hasRetainablePointerRepresentation()
401-
&& !E->getType()->is<AnyMetatypeType>());
400+
&& !E->getType()->getLValueOrInOutObjectType()
401+
->hasRetainablePointerRepresentation()
402+
&& !E->getType()->getLValueOrInOutObjectType()
403+
->is<AnyMetatypeType>());
402404

403405
// Loading classes or metatypes doesn't require their metadata.
404406
if (isa<LoadExpr>(E))
@@ -487,6 +489,11 @@ class FindCapturedVars : public ASTWalker {
487489
if (isa<ClassMetatypeToObjectExpr>(E)
488490
|| isa<ExistentialMetatypeToObjectExpr>(E))
489491
return false;
492+
493+
// Assigning an object doesn't require type metadata.
494+
if (auto assignment = dyn_cast<AssignExpr>(E))
495+
return !assignment->getSrc()->getType()
496+
->hasRetainablePointerRepresentation();
490497

491498
return true;
492499
}

test/ClangModules/objc_bridging_generics.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ extension AnimalContainer {
212212
y.apexPredator = x
213213
}
214214

215+
func doesntUseGenericParam5(y: T) {
216+
var x = y
217+
x = y
218+
_ = x
219+
}
220+
func doesntUseGenericParam6(y: T?) {
221+
var x = y
222+
x = y
223+
_ = x
224+
}
225+
215226
// expected-error@+1{{extension of a generic Objective-C class cannot access the class's generic parameters}}
216227
func usesGenericParamA(_ x: T) {
217228
_ = T(noise: x) // expected-note{{used here}}

0 commit comments

Comments
 (0)