Skip to content

Commit 70b982f

Browse files
authored
Merge pull request #64468 from hyp/eng/limit-stdlib-exposure
[interop][SwiftToCxx] ensure we always expose limited set of APIs fro…
2 parents 0c214fe + 5ca0b5a commit 70b982f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,8 +2784,12 @@ static bool isExposedToThisModule(const ModuleDecl &M, const ValueDecl *VD,
27842784
if (VD->hasClangNode())
27852785
return true;
27862786
auto *mc = VD->getModuleContext();
2787-
if (mc == &M || mc->isStdlibModule())
2787+
if (mc == &M)
27882788
return true;
2789+
// Only certain declarations are exposed from
2790+
// the standard library.
2791+
if (mc->isStdlibModule())
2792+
return hasExposeAttr(VD);
27892793
return exposedModules.count(mc->getName().str());
27902794
}
27912795

test/Interop/SwiftToCxx/enums/swift-enum-implementation.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/enums.h -Wno-unused-private-field -Wno-unused-function)
66

7+
// RUN: %target-swift-frontend %s -typecheck -module-name Enums -enable-experimental-cxx-interop -emit-clang-header-path %t/enums-default.h
8+
// RUN: %FileCheck %s < %t/enums-default.h
9+
710
public enum E {
811
case x(Double)
912
case y(UnsafeRawPointer?)
@@ -25,6 +28,11 @@ public enum E {
2528
}
2629
}
2730

31+
public enum E2 {
32+
case foobar
33+
case baz
34+
}
35+
2836
public struct S {
2937
public var x: Int64
3038

@@ -166,6 +174,15 @@ public struct S {
166174
// CHECK-NEXT: #endif
167175
// CHECK-NEXT: vwTable->initializeWithTake(destStorage, srcStorage, metadata._0);
168176
// CHECK-NEXT: }
177+
178+
// CHECK: class SWIFT_SYMBOL({{.*}}) E2 final {
179+
// CHECK: SWIFT_INLINE_THUNK operator cases() const {
180+
// CHECK: }
181+
// CHECK-NEXT: }
182+
// CHECK-EMPTY:
183+
// CHECK-NEXT: SWIFT_INLINE_THUNK swift::Int getHashValue() const SWIFT_SYMBOL({{.*}});
184+
// CHECK-NEXT: private:
185+
169186
// CHECK: namespace Enums SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Enums") {
170187
// CHECK: SWIFT_INLINE_THUNK E E::_impl_x::operator()(double val) const {
171188
// CHECK-NEXT: auto result = E::_make();

0 commit comments

Comments
 (0)