Skip to content
Open
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
28 changes: 21 additions & 7 deletions lib/ClangImporter/SwiftifyDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,24 @@ static bool swiftifyImpl(ClangImporter::Implementation &Self,
}

bool isClangInstanceMethod =
isa<clang::CXXMethodDecl>(ClangDecl) &&
!isa<clang::CXXConstructorDecl>(ClangDecl) &&
cast<clang::CXXMethodDecl>(ClangDecl)->isInstance();
size_t swiftNumParams = MappedDecl->getParameters()->size() -
(ClangDecl->isVariadic() ? 1 : 0);
ASSERT((MappedDecl->isImportAsInstanceMember() == isClangInstanceMethod) ==
(getNumParams(ClangDecl) == swiftNumParams));
(isa<clang::CXXMethodDecl>(ClangDecl) &&
!isa<clang::CXXConstructorDecl>(ClangDecl) &&
cast<clang::CXXMethodDecl>(ClangDecl)->isInstance()) ||
(isa<clang::ObjCMethodDecl>(ClangDecl) &&
cast<clang::ObjCMethodDecl>(ClangDecl)->isInstanceMethod());

size_t swiftNumParams = MappedDecl->getParameters()->size();
if (MappedDecl->isInstanceMember() && !isClangInstanceMethod) {
ASSERT(MappedDecl->isImportAsInstanceMember());
swiftNumParams += 1;
}
if (getNumParams(ClangDecl) != swiftNumParams) {
DLOG("mismatching parameter lists");
assert(ClangDecl->isVariadic() ||
MappedDecl->getForeignErrorConvention().has_value() ||
MappedDecl->getForeignAsyncConvention().has_value());
return false;
}

size_t selfParamIndex = MappedDecl->isImportAsInstanceMember()
? MappedDecl->getSelfIndex()
Expand Down Expand Up @@ -531,6 +542,9 @@ class SwiftifyProtocolInfoPrinter : public SwiftifyInfoPrinter {
void printMethodSignature(const FuncDecl *Method) {
auto options =
PrintOptions::printForDiagnostics(AccessLevel::Private, true);
for (const auto *attr : Method->getAttrs()) {
options.ExcludeAttrList.push_back(attr->getKind());
}
StreamPrinter printer(out);
Method->print(printer, options);
}
Expand Down
2 changes: 2 additions & 0 deletions test/Interop/C/swiftify-import/Inputs/counted-by.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ void hexLiteral(int * __counted_by(0xfa) p);
void binaryLiteral(int * __counted_by(0b10) p);

void octalLiteral(int * __counted_by(0777) p);

void variadic(int len, int * __counted_by(len) p, ...);
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} longLiteral
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} sizeofType
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} sizeofParam
// CHECK-NOT: @_alwaysEmitIntoClient {{.*}} variadic
11 changes: 11 additions & 0 deletions test/Interop/ObjC/swiftify-import/Inputs/objc-no-swiftify.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@
void autoreleaseParam(SomeClass * __autoreleasing * __counted_by(len) p, int len); // expected-note{{declared here}}

SomeClass * __autoreleasing * __counted_by(len) autoreleaseReturn(int len);

@interface NSError
@end

@interface NSData
@end

@protocol Foo
- (void)errorAsTry:(int) len : (int * __counted_by(len)) p error:(NSError * *) error;
- (void)completionHandlerAsAsync:(int) len : (int * __counted_by(len)) p completionHandler:(void (^)(NSData * data, NSError *)) completionHandler;
@end
15 changes: 12 additions & 3 deletions test/Interop/ObjC/swiftify-import/objc-no-swiftify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import NoSwiftifyClang

// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload public func callAutoreleaseParam
// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload public func callAutoreleaseReturn
// CHECK-NOT: @_alwaysEmitIntoClient @_disfavoredOverload

public func callAutoreleaseParam(_ p: UnsafeMutableBufferPointer<SomeClass>) {
// expected-error@+2{{missing argument for parameter #2 in call}}
Expand All @@ -19,4 +18,14 @@ public func callAutoreleaseParam(_ p: UnsafeMutableBufferPointer<SomeClass>) {
public func callAutoreleaseReturn() {
// expected-error@+1{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<SomeClass?>?' to specified type 'UnsafeMutableBufferPointer<SomeClass>'}}
let p: UnsafeMutableBufferPointer<SomeClass> = autoreleaseReturn(10)
}
}

public func callErrorAsTry(_ x: Foo, _ p: UnsafeMutablePointer<CInt>, _ error: AutoreleasingUnsafeMutablePointer<NSError?>) {
x.error(asTry: 10, p, error: error)
}

public func callCompletionHandlerAsAsync(_ x: Foo, _ p: UnsafeMutablePointer<CInt>) {
x.completionHandler(asAsync: 10, p, completionHandler: { (a: NSData?, b: NSError?) in
print("asdf")
})
}