Skip to content

Commit 6eb7057

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 68524a8 commit 6eb7057

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

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

9191+
// FIXME: for private macro generated functions we do not serialize the
9192+
// SILFunction's body anywhere triggering assertions.
9193+
if (ClangDecl->getAccess() == clang::AS_protected ||
9194+
ClangDecl->getAccess() == clang::AS_private)
9195+
return;
9196+
91919197
if (ClangDecl->getNumParams() != MappedDecl->getParameters()->size())
91929198
return;
91939199

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -emit-ir -I %swift_src_root/lib/ClangImporter/SwiftBridging -plugin-path %swift-plugin-dir %t/blessed.swift -module-name main -I %t/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+
//--- Inputs/swiftify-non-public.h
12+
#pragma once
13+
14+
#include "swift/bridging"
15+
#include <span>
16+
17+
using IntSpan = std::span<const int>;
18+
19+
class SWIFT_PRIVATE_FILEID("main/blessed.swift") MyClass {
20+
private:
21+
void takesSpan(IntSpan s [[clang::noescape]]) {}
22+
};
23+
24+
//--- Inputs/module.modulemap
25+
module SwiftifyNonPublic {
26+
requires cplusplus
27+
header "swiftify-non-public.h"
28+
}
29+
30+
//--- blessed.swift
31+
import CxxStdlib
32+
import SwiftifyNonPublic
33+
34+
extension MyClass {
35+
mutating func passesSpan(_ s: Span<CInt>) {
36+
takesSpan(s) // expected-error {{cannot convert value of type}}
37+
}
38+
}

0 commit comments

Comments
 (0)