Skip to content

Commit 1c9cfa1

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 1c9cfa1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9159,6 +9159,8 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
91599159
returnHasLifetimeInfo = true;
91609160
}
91619161
for (auto [index, clangParam] : llvm::enumerate(ClangDecl->parameters())) {
9162+
if (index >= MappedDecl->getParameters()->size())
9163+
break;
91629164
auto clangParamTy = clangParam->getType();
91639165
auto swiftParam = MappedDecl->getParameters()->get(index);
91649166
bool paramHasBoundsInfo = false;
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)