Skip to content

Commit 2fd4f56

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 (cherry picked from commit af8579f)
1 parent 7e59265 commit 2fd4f56

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
@@ -4663,7 +4663,7 @@ namespace {
46634663
auto loc = Impl.importSourceLoc(decl->getLocation());
46644664
auto dc = Impl.importDeclContextOf(
46654665
decl, importedName.getEffectiveContext());
4666-
4666+
46674667
SmallVector<GenericTypeParamDecl *, 4> genericParams;
46684668
for (auto &param : *decl->getTemplateParameters()) {
46694669
auto genericParamDecl =
@@ -5446,7 +5446,7 @@ namespace {
54465446
objcClass->getDeclaredType());
54475447
Impl.SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{result},
54485448
std::move(objcClass));
5449-
5449+
54505450
Identifier categoryName;
54515451
if (!decl->getName().empty())
54525452
categoryName = Impl.SwiftContext.getIdentifier(decl->getName());
@@ -9073,6 +9073,9 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
90739073
if (!ClangDecl)
90749074
return;
90759075

9076+
if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size())
9077+
return;
9078+
90769079
llvm::SmallString<128> MacroString;
90779080
// We only attach the macro if it will produce an overload. Any __counted_by
90789081
// will produce an overload, since UnsafeBufferPointer is still an improvement
@@ -9488,7 +9491,7 @@ ClangImporter::Implementation::importDeclImpl(const clang::NamedDecl *ClangDecl,
94889491
Result = importDecl(UnderlyingDecl, version);
94899492
SkippedOverTypedef = true;
94909493
}
9491-
9494+
94929495
if (!Result) {
94939496
SwiftDeclConverter converter(*this, version);
94949497
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)