Skip to content

Commit c8f8e86

Browse files
author
Gabor Horvath
committed
[cxx-interop] Handle vector types in escapability analysis
Whenever we have a vector type, the escpability depends on the escapability of the element type. This will enable us to consider more types like std::vector<simd::float3> as safe by default. rdar://157141552
1 parent a47d392 commit c8f8e86

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5346,6 +5346,14 @@ ClangTypeEscapability::evaluate(Evaluator &evaluator,
53465346
ClangTypeEscapability({elemTy, desc.impl, desc.annotationOnly}),
53475347
CxxEscapability::Unknown);
53485348
}
5349+
if (const auto *vecTy = desugared->getAs<clang::VectorType>()) {
5350+
return evaluateOrDefault(
5351+
evaluator,
5352+
ClangTypeEscapability(
5353+
{vecTy->getElementType()->getUnqualifiedDesugaredType(), desc.impl,
5354+
desc.annotationOnly}),
5355+
CxxEscapability::Unknown);
5356+
}
53495357

53505358
// Base cases
53515359
if (desugared->isAnyPointerType() || desugared->isBlockPointerType() ||
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -typecheck -verify -I %swift_src_root/lib/ClangImporter/SwiftBridging -Xcc -std=c++20 -I %t/Inputs %t/test.swift -strict-memory-safety -enable-experimental-feature LifetimeDependence -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1
4+
5+
// REQUIRES: objc_interop
6+
// REQUIRES: swift_feature_LifetimeDependence
7+
// REQUIRES: OS=macosx
8+
9+
//--- Inputs/module.modulemap
10+
module Test {
11+
header "nonescapable.h"
12+
requires cplusplus
13+
}
14+
15+
//--- Inputs/nonescapable.h
16+
#pragma once
17+
18+
#include <simd/simd.h>
19+
#include <vector>
20+
21+
using VecOfSimd = std::vector<simd::float3>;
22+
using MySimd = simd::float3;
23+
24+
//--- test.swift
25+
import Test
26+
import CxxStdlib
27+
28+
func simdConsideredSafe(x : MySimd) {
29+
let _ = x
30+
}
31+
32+
func simdVecConsideredSafe(x : VecOfSimd) {
33+
let _ = x
34+
}

0 commit comments

Comments
 (0)