Skip to content

Commit d43ff2d

Browse files
committed
[ClangImporter] Enable parsing bounds safety attributes in C++
This allows combining __counted_by and std::span for safe interop. Previously we disabled this in C++ mode due to issues when bounds attributes occurred directly or indirectly in templated contexts, but this has now been resolved on the clang side.
1 parent 957db2c commit d43ff2d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ void importer::getNormalInvocationArguments(
566566
}
567567
}
568568

569-
if (LangOpts.hasFeature(Feature::SafeInteropWrappers) &&
570-
!LangOpts.EnableCXXInterop)
569+
if (LangOpts.hasFeature(Feature::SafeInteropWrappers))
571570
invocationArgStrs.push_back("-fexperimental-bounds-safety-attributes");
572571

573572
// Set C language options.

test/Interop/Cxx/stdlib/std-span-interface.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import CxxStdlib
3333
// CHECK-NEXT: @lifetime(borrow v)
3434
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func funcWithSafeWrapper3(_ v: borrowing VecOfInt) -> Span<CInt>
3535
// CHECK-NEXT: @lifetime(p)
36-
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func mixedFuncWithSafeWrapper1(_ p: UnsafePointer<Int32>!, _ len: Int32) -> Span<CInt>
37-
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper3(_ s: Span<CInt>, _ p: UnsafeMutablePointer<Int32>!, _ len: Int32)
38-
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper4(_ s: Span<CInt>, _ p: UnsafePointer<Int32>!, _ len: Int32)
36+
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper1(_ p: Span<Int32>) -> Span<CInt>
37+
// CHECK-NEXT: @lifetime(borrow v)
38+
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func mixedFuncWithSafeWrapper2(_ v: borrowing VecOfInt, _ len: Int32) -> UnsafeBufferPointer<Int32>
39+
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper3(_ s: Span<CInt>, _ p: UnsafeMutableBufferPointer<Int32>)
40+
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper4(_ s: Span<CInt>, _ p: Span<Int32>)
41+
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper5(_ s: ConstSpanOfInt, _ p: Span<Int32>)
42+
// CHECK-NEXT: @_alwaysEmitIntoClient public func mixedFuncWithSafeWrapper6(_ s: ConstSpanOfInt, _ p: UnsafeMutableBufferPointer<Int32>)

0 commit comments

Comments
 (0)