Skip to content

Commit 54ec06d

Browse files
authored
Merge pull request #22792 from slavapestov/fix-remoteast-asan-failure
RemoteAST: Try to fix a use-after-free in swift-remoteast-test
2 parents 4ced0af + 82f8d3f commit 54ec06d

File tree

9 files changed

+48
-1
lines changed

9 files changed

+48
-1
lines changed

test/RemoteAST/existentials.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@_silgen_name("printDynamicTypeAndAddressForExistential")
66
func printDynamicTypeAndAddressForExistential<T>(_: T)
77

8+
@_silgen_name("stopRemoteAST")
9+
func stopRemoteAST()
10+
811
struct MyStruct<T, U, V> {
912
let x: T
1013
let y: U
@@ -49,3 +52,5 @@ printDynamicTypeAndAddressForExistential(q)
4952
// CHECK-NEXT: Any.Type
5053
let metatype : Any.Type = Any.self
5154
printDynamicTypeAndAddressForExistential(metatype)
55+
56+
stopRemoteAST()

test/RemoteAST/existentials_objc.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import Foundation
88
@_silgen_name("printDynamicTypeAndAddressForExistential")
99
func printDynamicTypeAndAddressForExistential<T>(_: T)
1010

11+
@_silgen_name("stopRemoteAST")
12+
func stopRemoteAST()
13+
1114
// CHECK: NSObject
1215
printDynamicTypeAndAddressForExistential(NSObject() as AnyObject)
1316
@@ -41,3 +44,5 @@ class ClassError : NSError {
4144

4245
// CHECK: ClassError
4346
printDynamicTypeAndAddressForExistential(ClassError() as Error)
47+
48+
stopRemoteAST()

test/RemoteAST/extensions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@_silgen_name("printMetadataType")
66
func printType(_: Any.Type)
77

8+
@_silgen_name("stopRemoteAST")
9+
func stopRemoteAST()
10+
811
extension Int {
912
struct Inner { }
1013
}
@@ -76,3 +79,5 @@ extension A where T: AnyObject {
7679

7780
// CHECK: A<C, Int>.ViaAnyObject
7881
printType(A<C, Int>.ViaAnyObject.self)
82+
83+
stopRemoteAST()

test/RemoteAST/foreign_types.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import ErrorEnums
1010
@_silgen_name("printMetadataType")
1111
func printType(_: Any.Type)
1212

13+
@_silgen_name("stopRemoteAST")
14+
func stopRemoteAST()
15+
1316
printType(CCRefrigerator.self)
1417
// CHECK: found type: CCRefrigerator
1518

@@ -30,3 +33,5 @@ printType(Wrapper.MemberEnum.self)
3033

3134
printType(WrapperByAttribute.self)
3235
// CHECK: found type: WrapperByAttribute{{$}}
36+
37+
stopRemoteAST()

test/RemoteAST/member_offsets.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ func printTypeMemberOffset(_: Any.Type, _: StaticString)
99
@_silgen_name("printTypeMetadataMemberOffset")
1010
func printTypeMetadataMemberOffset(_: Any.Type, _: StaticString)
1111

12+
@_silgen_name("stopRemoteAST")
13+
func stopRemoteAST()
14+
1215
printTypeMemberOffset((Int,Bool,Float,Bool,Int16).self, "0")
1316
// CHECK: found offset: 0
1417
@@ -78,3 +81,5 @@ printTypeMemberOffset(B<Float>.self, "e")
7881
7982
printTypeMemberOffset(B<Float>.self, "f")
8083
// CHECK-NEXT: type has no member named 'f'
84+
85+
stopRemoteAST()

test/RemoteAST/nominal_types.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@_silgen_name("printMetadataType")
66
func printType(_: Any.Type)
77

8+
@_silgen_name("stopRemoteAST")
9+
func stopRemoteAST()
10+
811
printType(Int.self)
912
// CHECK: Int
1013

@@ -137,3 +140,5 @@ struct N {
137140
}
138141
}
139142
N.testPrivate()
143+
144+
stopRemoteAST()

test/RemoteAST/objc_classes.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ func printType(_: Any.Type)
1111
@_silgen_name("printHeapMetadataType")
1212
func printDynamicType(_: AnyObject)
1313

14+
@_silgen_name("stopRemoteAST")
15+
func stopRemoteAST()
16+
1417
printType(NSString.self)
1518
// CHECK: NSString
1619

@@ -42,3 +45,5 @@ printType(OurObjCProtocol.self)
4245

4346
printType(Optional<OurObjCProtocol>.self)
4447
// CHECK: Optional<OurObjCProtocol & AnyObject>
48+
49+
stopRemoteAST()

test/RemoteAST/structural_types.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
@_silgen_name("printMetadataType")
66
func printType(_: Any.Type)
77

8+
@_silgen_name("stopRemoteAST")
9+
func stopRemoteAST()
10+
811
typealias Fn1 = () -> ()
912
printType(Fn1.self)
1013
// CHECK: found type: () -> ()
@@ -70,3 +73,5 @@ func foo<T>(_: T) {
7073

7174
foo() { (x: Int) -> Int in return x }
7275
// CHECK: found type: (Int) -> Int
76+
77+
stopRemoteAST()

tools/swift-remoteast-test/swift-remoteast-test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ using namespace swift::remoteAST;
4242
static ASTContext *context = nullptr;
4343

4444
/// The RemoteAST for the code we're running.
45-
std::shared_ptr<MemoryReader> reader;
4645
std::unique_ptr<RemoteASTContext> remoteContext;
4746

4847
static RemoteASTContext &getRemoteASTContext() {
@@ -174,6 +173,14 @@ printDynamicTypeAndAddressForExistential(void *object,
174173
}
175174
}
176175

176+
// FIXME: swiftcall
177+
/// func stopRemoteAST(_: AnyObject)
178+
LLVM_ATTRIBUTE_USED extern "C" void SWIFT_REMOTEAST_TEST_ABI
179+
stopRemoteAST() {
180+
if (remoteContext)
181+
remoteContext.reset();
182+
}
183+
177184
namespace {
178185

179186
struct Observer : public FrontendObserver {

0 commit comments

Comments
 (0)