Skip to content

RemoteAST: Try to fix a use-after-free in swift-remoteast-test #22792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/RemoteAST/existentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@_silgen_name("printDynamicTypeAndAddressForExistential")
func printDynamicTypeAndAddressForExistential<T>(_: T)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

struct MyStruct<T, U, V> {
let x: T
let y: U
Expand Down Expand Up @@ -49,3 +52,5 @@ printDynamicTypeAndAddressForExistential(q)
// CHECK-NEXT: Any.Type
let metatype : Any.Type = Any.self
printDynamicTypeAndAddressForExistential(metatype)

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/existentials_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import Foundation
@_silgen_name("printDynamicTypeAndAddressForExistential")
func printDynamicTypeAndAddressForExistential<T>(_: T)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

// CHECK: NSObject
printDynamicTypeAndAddressForExistential(NSObject() as AnyObject)

Expand Down Expand Up @@ -41,3 +44,5 @@ class ClassError : NSError {

// CHECK: ClassError
printDynamicTypeAndAddressForExistential(ClassError() as Error)

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@_silgen_name("printMetadataType")
func printType(_: Any.Type)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

extension Int {
struct Inner { }
}
Expand Down Expand Up @@ -76,3 +79,5 @@ extension A where T: AnyObject {

// CHECK: A<C, Int>.ViaAnyObject
printType(A<C, Int>.ViaAnyObject.self)

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/foreign_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import ErrorEnums
@_silgen_name("printMetadataType")
func printType(_: Any.Type)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

printType(CCRefrigerator.self)
// CHECK: found type: CCRefrigerator

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

printType(WrapperByAttribute.self)
// CHECK: found type: WrapperByAttribute{{$}}

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/member_offsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ func printTypeMemberOffset(_: Any.Type, _: StaticString)
@_silgen_name("printTypeMetadataMemberOffset")
func printTypeMetadataMemberOffset(_: Any.Type, _: StaticString)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

printTypeMemberOffset((Int,Bool,Float,Bool,Int16).self, "0")
// CHECK: found offset: 0

Expand Down Expand Up @@ -78,3 +81,5 @@ printTypeMemberOffset(B<Float>.self, "e")

printTypeMemberOffset(B<Float>.self, "f")
// CHECK-NEXT: type has no member named 'f'

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/nominal_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@_silgen_name("printMetadataType")
func printType(_: Any.Type)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

printType(Int.self)
// CHECK: Int

Expand Down Expand Up @@ -137,3 +140,5 @@ struct N {
}
}
N.testPrivate()

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/objc_classes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ func printType(_: Any.Type)
@_silgen_name("printHeapMetadataType")
func printDynamicType(_: AnyObject)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

printType(NSString.self)
// CHECK: NSString

Expand Down Expand Up @@ -42,3 +45,5 @@ printType(OurObjCProtocol.self)

printType(Optional<OurObjCProtocol>.self)
// CHECK: Optional<OurObjCProtocol & AnyObject>

stopRemoteAST()
5 changes: 5 additions & 0 deletions test/RemoteAST/structural_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@_silgen_name("printMetadataType")
func printType(_: Any.Type)

@_silgen_name("stopRemoteAST")
func stopRemoteAST()

typealias Fn1 = () -> ()
printType(Fn1.self)
// CHECK: found type: () -> ()
Expand Down Expand Up @@ -70,3 +73,5 @@ func foo<T>(_: T) {

foo() { (x: Int) -> Int in return x }
// CHECK: found type: (Int) -> Int

stopRemoteAST()
9 changes: 8 additions & 1 deletion tools/swift-remoteast-test/swift-remoteast-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ using namespace swift::remoteAST;
static ASTContext *context = nullptr;

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

static RemoteASTContext &getRemoteASTContext() {
Expand Down Expand Up @@ -174,6 +173,14 @@ printDynamicTypeAndAddressForExistential(void *object,
}
}

// FIXME: swiftcall
/// func stopRemoteAST(_: AnyObject)
LLVM_ATTRIBUTE_USED extern "C" void SWIFT_REMOTEAST_TEST_ABI
stopRemoteAST() {
if (remoteContext)
remoteContext.reset();
}

namespace {

struct Observer : public FrontendObserver {
Expand Down