Skip to content

Commit dd2f521

Browse files
Merge pull request #82104 from swiftlang/gaborh/swiftify-private-on-6.2
[6.2][cxx-interop] Avoid swiftifying private and protected methods
2 parents 90f6a8a + 7548cbf commit dd2f521

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
@@ -9164,6 +9164,12 @@ void ClangImporter::Implementation::swiftify(FuncDecl *MappedDecl) {
91649164
if (!ClangDecl)
91659165
return;
91669166

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

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)