Skip to content

Commit 7ce30d7

Browse files
committed
Revert "Add new pattern in SILCombine to optimize redundant thick to objc metatype conversions (#31595)"
This reverts commit 488333c. It looks like this might have caused a heap-use-after free on an asan bot. rdar://63135437
1 parent 8500cf8 commit 7ce30d7

File tree

2 files changed

+0
-55
lines changed

2 files changed

+0
-55
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ SILCombiner::visitThickToObjCMetatypeInst(ThickToObjCMetatypeInst *TTOCMI) {
452452
if (CastOpt.optimizeMetatypeConversion(TTOCMI, MetatypeRepresentation::Thick))
453453
MadeChange = true;
454454

455-
if (auto *OCTTMI = dyn_cast<ObjCToThickMetatypeInst>(TTOCMI->getOperand())) {
456-
TTOCMI->replaceAllUsesWith(OCTTMI->getOperand());
457-
return eraseInstFromFunction(*TTOCMI);
458-
}
459455
return nullptr;
460456
}
461457

@@ -476,10 +472,6 @@ SILCombiner::visitObjCToThickMetatypeInst(ObjCToThickMetatypeInst *OCTTMI) {
476472
if (CastOpt.optimizeMetatypeConversion(OCTTMI, MetatypeRepresentation::ObjC))
477473
MadeChange = true;
478474

479-
if (auto *TTOCMI = dyn_cast<ThickToObjCMetatypeInst>(OCTTMI->getOperand())) {
480-
OCTTMI->replaceAllUsesWith(TTOCMI->getOperand());
481-
return eraseInstFromFunction(*OCTTMI);
482-
}
483475
return nullptr;
484476
}
485477

test/SILOptimizer/peephole_thick_to_objc_metatype.sil

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import Builtin
88
import Swift
99
import SwiftShims
1010

11-
import Foundation
12-
1311
@objc(XX) protocol X {
1412
}
1513

@@ -117,48 +115,3 @@ bb0(%0 : $T):
117115
strong_release %0 : $T
118116
return %3 : $@thick T.Type
119117
}
120-
121-
// CHECK-LABEL: sil @$test_peephole_objc_to_thick_to_objc :
122-
// CHECK: [[T:%.*]] = apply
123-
// CHECK-NOT: objc_to_thick_metatype
124-
// CHECK-NOT: thick_to_objc_metatype
125-
// CHECK: enum $Optional<@objc_metatype AnyObject.Type>, #Optional.some!enumelt, [[T]] : $@objc_metatype AnyObject.Type
126-
// CHECK: } // end sil function '$test_peephole_objc_to_thick_to_objc'
127-
128-
sil @$test_peephole_objc_to_thick_to_objc : $@convention(thin) (@guaranteed NSObject) -> Optional<UnsafeMutablePointer<OpaquePointer>> {
129-
// %0 "obj" // users: %3, %2, %1
130-
bb0(%0 : $NSObject):
131-
debug_value %0 : $NSObject, let, name "obj", argno 1 // id: %1
132-
%2 = objc_method %0 : $NSObject, #NSObject.classForCoder!getter.foreign : (NSObject) -> () -> AnyObject.Type, $@convention(objc_method) (NSObject) -> @objc_metatype AnyObject.Type // user: %3
133-
%3 = apply %2(%0) : $@convention(objc_method) (NSObject) -> @objc_metatype AnyObject.Type // user: %4
134-
%4 = objc_to_thick_metatype %3 : $@objc_metatype AnyObject.Type to $@thick AnyObject.Type // users: %6, %5
135-
debug_value %4 : $@thick AnyObject.Type, let, name "c" // id: %5
136-
%6 = thick_to_objc_metatype %4 : $@thick AnyObject.Type to $@objc_metatype AnyObject.Type // user: %7
137-
%7 = enum $Optional<@objc_metatype AnyObject.Type>, #Optional.some!enumelt, %6 : $@objc_metatype AnyObject.Type // user: %10
138-
%8 = enum $Optional<UnsafeMutablePointer<UInt32>>, #Optional.none!enumelt // user: %10
139-
// function_ref class_copyMethodList
140-
%9 = function_ref @class_copyMethodList : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>> // user: %10
141-
%10 = apply %9(%7, %8) : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>> // users: %12, %11
142-
debug_value %10 : $Optional<UnsafeMutablePointer<OpaquePointer>>, let, name "l" // id: %11
143-
return %10 : $Optional<UnsafeMutablePointer<OpaquePointer>> // id: %12
144-
}
145-
146-
// CHECK-LABEL: sil @$test_peephole_thick_to_objc_to_thick :
147-
// CHECK: [[T:%.*]] = apply
148-
// CHECK-NOT: thick_to_objc_metatype
149-
// CHECK-NOT: objc_to_thick_metatype
150-
// CHECK: return [[T]]
151-
// CHECK: } // end sil function '$test_peephole_thick_to_objc_to_thick'
152-
153-
sil @$test_peephole_thick_to_objc_to_thick : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type {
154-
bb0(%0 : $AnyObject):
155-
%func = function_ref @foo : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type
156-
%res = apply %func(%0) : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type
157-
%objctype = thick_to_objc_metatype %res : $@thick AnyObject.Type to $@objc_metatype AnyObject.Type
158-
%thicktype = objc_to_thick_metatype %objctype : $@objc_metatype AnyObject.Type to $@thick AnyObject.Type
159-
return %thicktype : $@thick AnyObject.Type
160-
}
161-
162-
// class_copyMethodList
163-
sil [serializable] [clang class_copyMethodList] @class_copyMethodList : $@convention(c) (Optional<@objc_metatype AnyObject.Type>, Optional<UnsafeMutablePointer<UInt32>>) -> Optional<UnsafeMutablePointer<OpaquePointer>>
164-
sil [serializable] @foo : $@convention(thin) (@guaranteed AnyObject) -> @thick AnyObject.Type

0 commit comments

Comments
 (0)