Skip to content

Commit af8579f

Browse files
committed
[Swiftify] Fix crash calling cgImage.width
cgImage.width calls the C function, CGImageGetWidth(CGImageRef). Swift representation and Clang representation of this function seem to have a parameter number mismatch, causing swiftify function to crash. rdar://149691207
1 parent d788713 commit af8579f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4712,7 +4712,7 @@ namespace {
47124712
auto loc = Impl.importSourceLoc(decl->getLocation());
47134713
auto dc = Impl.importDeclContextOf(
47144714
decl, importedName.getEffectiveContext());
4715-
4715+
47164716
SmallVector<GenericTypeParamDecl *, 4> genericParams;
47174717
for (auto &param : *decl->getTemplateParameters()) {
47184718
auto genericParamDecl =
@@ -5495,7 +5495,7 @@ namespace {
54955495
objcClass->getDeclaredType());
54965496
Impl.SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{result},
54975497
std::move(objcClass));
5498-
5498+
54995499
Identifier categoryName;
55005500
if (!decl->getName().empty())
55015501
categoryName = Impl.SwiftContext.getIdentifier(decl->getName());
@@ -9122,6 +9122,9 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
91229122
if (!ClangDecl)
91239123
return;
91249124

9125+
if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size())
9126+
return;
9127+
91259128
llvm::SmallString<128> MacroString;
91269129
// We only attach the macro if it will produce an overload. Any __counted_by
91279130
// will produce an overload, since UnsafeBufferPointer is still an improvement
@@ -9537,7 +9540,7 @@ ClangImporter::Implementation::importDeclImpl(const clang::NamedDecl *ClangDecl,
95379540
Result = importDecl(UnderlyingDecl, version);
95389541
SkippedOverTypedef = true;
95399542
}
9540-
9543+
95419544
if (!Result) {
95429545
SwiftDeclConverter converter(*this, version);
95439546
Result = converter.Visit(ClangDecl);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: swift_feature_SafeInteropWrappers
2+
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t
5+
// RUN: %target-swift-ide-test -plugin-path %swift-plugin-dir -I %t/Inputs -enable-experimental-feature SafeInteropWrappers -print-module -module-to-print=Method -source-filename=x
6+
// RUN: %target-swift-frontend -plugin-path %swift-plugin-dir -I %t/Inputs -enable-experimental-feature SafeInteropWrappers %t/method.swift -dump-macro-expansions -typecheck -verify
7+
8+
// REQUIRES: objc_interop
9+
10+
//--- Inputs/module.modulemap
11+
module Method {
12+
header "method.h"
13+
}
14+
15+
//--- method.swift
16+
import CoreImage
17+
18+
func test(_ image: CGImage) -> Int {
19+
return image.width
20+
}

0 commit comments

Comments
 (0)