Merge remote-tracking branch 'origin/master' into master-next

This commit is contained in:
swift_jenkins
2019-11-19 10:39:18 -08:00
6 changed files with 65 additions and 3 deletions

View File

@@ -1337,6 +1337,12 @@ static bool processCommandLineAndRunImmediately(CompilerInvocation &Invocation,
ProcessCmdLine(opts.ImmediateArgv.begin(), opts.ImmediateArgv.end());
Instance.setSILModule(std::move(SM));
PrettyStackTraceStringAction trace(
"running user code",
MSF.is<SourceFile *>() ? MSF.get<SourceFile *>()->getFilename()
: MSF.get<ModuleDecl *>()->getModuleFilename());
ReturnValue =
RunImmediately(Instance, CmdLine, IRGenOpts, Invocation.getSILOptions());
return Instance.getASTContext().hadError();

View File

@@ -37,6 +37,7 @@
#include "llvm/Support/Compiler.h"
#if SWIFT_OBJC_INTEROP
#include "swift/Runtime/ObjCBridge.h"
#include "SwiftObject.h"
#include "SwiftValue.h"
#endif
@@ -2330,9 +2331,10 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
case MetadataKind::Class:
case MetadataKind::ObjCClassWrapper:
#if SWIFT_OBJC_INTEROP
// If the destination type is an NSError, and the source type is an
// Error, then the cast can succeed by NSError bridging.
if (targetType == getNSErrorMetadata()) {
// If the destination type is an NSError or NSObject, and the source type
// is an Error, then the cast can succeed by NSError bridging.
if (targetType == getNSErrorMetadata() ||
targetType == getNSObjectMetadata()) {
// Don't rebridge if the source is already some kind of NSError.
if (srcType->isAnyClass()
&& swift_dynamicCastObjCClass(*reinterpret_cast<id*>(src),

View File

@@ -29,6 +29,7 @@
#if SWIFT_OBJC_INTEROP
#if __OBJC__
// Source code: "SwiftObject"
// Real class name: mangled "Swift._SwiftObject"
@@ -83,5 +84,13 @@ id getDescription(OpaqueValue *value, const Metadata *type);
}
#endif
#endif
namespace swift {
/// Get the NSObject metadata.
const Metadata *getNSObjectMetadata();
}
#endif

View File

@@ -1552,6 +1552,11 @@ void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
free(nullTerminatedFilename);
}
const Metadata *swift::getNSObjectMetadata() {
return SWIFT_LAZY_CONSTANT(
swift_getObjCClassMetadata((const ClassMetadata *)[NSObject class]));
}
#endif
const ClassMetadata *swift::getRootSuperclass() {

View File

@@ -0,0 +1,15 @@
// RUN: echo %s > %t.filelist.txt
// RUN: not --crash %target-swift-frontend -interpret -filelist %t.filelist.txt 2>&1 | %FileCheck %s
// CHECK: Stack dump:
// CHECK-NEXT: Program arguments:
// CHECK-NEXT: Swift version
// CHECK-NEXT: Contents of {{.*}}.filelist.txt:
// CHECK-NEXT: ---
// CHECK-NEXT: crash-in-user-code.swift
// CHECK-NEXT: ---
// CHECK-NEXT: While running user code "{{.*}}crash-in-user-code.swift"
let x: Int? = nil
x!

View File

@@ -767,4 +767,29 @@ ErrorBridgingTests.test("@objc error domains for nested types") {
String(reflecting: NonPrintAsObjCError.self))
}
@inline(never)
@_optimize(none)
func anyToAny<T, U>(_ a: T, _ : U.Type) -> U {
return a as! U
}
ErrorBridgingTests.test("error-to-NSObject casts") {
let error = MyCustomizedError(code: 12345)
// Unconditional cast
let nsErrorAsObject1 = unconditionalCast(error, to: NSObject.self)
let nsError1 = unconditionalCast(nsErrorAsObject1, to: NSError.self)
expectEqual("custom", nsError1.domain)
expectEqual(12345, nsError1.code)
// Conditional cast
let nsErrorAsObject2 = conditionalCast(error, to: NSObject.self)!
let nsError2 = unconditionalCast(nsErrorAsObject2, to: NSError.self)
expectEqual("custom", nsError2.domain)
expectEqual(12345, nsError2.code)
// "is" check
expectTrue(error is NSObject)
}
runAllTests()