Skip to content

Commit ed1fe30

Browse files
author
Gabor Horvath
committed
[cxx-interop] Avoid swiftifying private and protected methods
The generated overloads do not get seralized and later on the compiler crashes due to the missing body of the SILFunction. This PR works this problem around by not generating these overloads. We plan to address the serialization issue later. rdar://152181531
1 parent 87e536e commit ed1fe30

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9165,6 +9165,12 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
91659165
if (!ClangDecl)
91669166
return;
91679167

9168+
// FIXME: for private macro generated functions we do not serialize the
9169+
// SILFunction's body anywhere triggering assertions.
9170+
if (ClangDecl->getAccess() == clang::AS_protected ||
9171+
ClangDecl->getAccess() == clang::AS_private)
9172+
return;
9173+
91689174
if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size())
91699175
return;
91709176

test/Interop/Cxx/class/access/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ module NonPublic {
1313
header "non-public.h"
1414
}
1515

16+
module SwiftifyNonPublic {
17+
requires cplusplus
18+
header "swiftify-non-public.h"
19+
}
20+
1621
module NonPublicInheritance {
1722
requires cplusplus
1823
header "non-public-inheritance.h"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <span>
4+
5+
using IntSpan = std::span<const int>;
6+
7+
class __attribute__((__swift_attr__("private_fileid:main/blessed.swift"))) MyClass {
8+
private:
9+
void takesSpan(IntSpan s [[clang::noescape]]) {}
10+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-ir -plugin-path %swift-plugin-dir %t/blessed.swift -module-name main -I %S/Inputs -o %t/out -Xcc -std=c++20 -cxx-interoperability-mode=default -enable-experimental-feature SafeInteropWrappers -verify
5+
6+
// REQUIRES: swift_feature_SafeInteropWrappers
7+
8+
// FIXME swift-ci linux tests do not support std::span
9+
// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi
10+
11+
//--- blessed.swift
12+
import CxxStdlib
13+
import SwiftifyNonPublic
14+
15+
extension MyClass {
16+
mutating func passesSpan(_ s: Span<CInt>) {
17+
takesSpan(s) // expected-error {{cannot convert value of type}}
18+
}
19+
}

0 commit comments

Comments
 (0)