Skip to content

Commit 25cfcd9

Browse files
committed
[interop][SwiftToCxx] Referenced clang decls are always exposed
1 parent 9ca5492 commit 25cfcd9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,9 @@ static bool hasExposeAttr(const ValueDecl *VD, bool isExtension = false) {
25762576
return true;
25772577
return false;
25782578
}
2579+
// Clang decls don't need to be explicitly exposed.
2580+
if (VD->hasClangNode())
2581+
return true;
25792582
if (VD->getAttrs().hasAttribute<ExposeAttr>())
25802583
return true;
25812584
if (const auto *NMT = dyn_cast<NominalTypeDecl>(VD->getDeclContext()))

test/Interop/CxxToSwiftToCxx/bridge-cxx-struct-back-to-cxx.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
// RUN: %FileCheck %s < %t/UseCxxTy.h
77

8+
// RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxxTy -emit-clang-header-path %t/UseCxxTyExposeOnly.h -I %t -enable-experimental-cxx-interop
9+
10+
// RUN: %FileCheck %s < %t/UseCxxTyExposeOnly.h
11+
812
// FIXME: remove once https://github.com/apple/swift/pull/60971 lands.
913
// RUN: echo "#include \"header.h\"" > %t/full-cxx-swift-cxx-bridging.h
1014
// RUN: cat %t/UseCxxTy.h >> %t/full-cxx-swift-cxx-bridging.h
@@ -51,32 +55,40 @@ module CxxTest {
5155
//--- use-cxx-types.swift
5256
import CxxTest
5357

58+
@_expose(Cxx)
5459
public func retNonTrivial() -> ns.NonTrivialTemplate<CInt> {
5560
return ns.NonTrivialTemplate<CInt>()
5661
}
5762

63+
@_expose(Cxx)
5864
public func retNonTrivial2() -> ns.NonTrivialTemplate<ns.TrivialinNS> {
5965
return ns.NonTrivialTemplate<ns.TrivialinNS>()
6066
}
6167

68+
@_expose(Cxx)
6269
public func retNonTrivialImplicitMove() -> ns.NonTrivialImplicitMove {
6370
return ns.NonTrivialImplicitMove()
6471
}
6572

73+
@_expose(Cxx)
6674
public func retNonTrivialTypeAlias() -> ns.TypeAlias {
6775
return ns.TypeAlias()
6876
}
6977

78+
@_expose(Cxx)
7079
public func retTrivial() -> Trivial {
7180
return Trivial()
7281
}
7382

83+
@_expose(Cxx)
7484
public func takeNonTrivial2(_ x: ns.NonTrivialTemplate<ns.TrivialinNS>) {
7585
}
7686

87+
@_expose(Cxx)
7788
public func takeTrivial(_ x: Trivial) {
7889
}
7990

91+
@_expose(Cxx)
8092
public func takeTrivialInout(_ x: inout Trivial) {
8193
}
8294

test/Interop/ObjCToSwiftToObjCxx/bridge-objc-types-back-to-objcxx.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
// RUN: %FileCheck %s < %t/UseObjCTy.h
77

8+
// RUN: %target-swift-frontend -typecheck %t/use-objc-types.swift -typecheck -module-name UseObjCTy -emit-clang-header-path %t/UseObjCTyExposeOnly.h -I %t -enable-experimental-cxx-interop
9+
10+
// RUN: %FileCheck %s < %t/UseObjCTyExposeOnly.h
11+
812
// FIXME: remove once https://github.com/apple/swift/pull/60971 lands.
913
// RUN: echo "#include \"header.h\"" > %t/full-header.h
1014
// RUN: cat %t/UseObjCTy.h >> %t/full-header.h
@@ -27,19 +31,24 @@ module ObjCTest {
2731
//--- use-objc-types.swift
2832
import ObjCTest
2933

34+
@_expose(Cxx)
3035
public func retObjClass() -> ObjCKlass {
3136
return ObjCKlass()
3237
}
3338

39+
@_expose(Cxx)
3440
public func takeObjCClass(_ x: ObjCKlass) {
3541
}
3642

43+
@_expose(Cxx)
3744
public func takeObjCClassInout(_ x: inout ObjCKlass) {
3845
}
3946

47+
@_expose(Cxx)
4048
public func takeObjCClassNullable(_ x: ObjCKlass?) {
4149
}
4250

51+
@_expose(Cxx)
4352
public func retObjClassNullable() -> ObjCKlass? {
4453
return nil
4554
}

0 commit comments

Comments
 (0)