Skip to content

Commit 91b4fab

Browse files
authored
Merge pull request #83542 from Xazax-hun/simd-is-escapable
[cxx-interop] Handle vector types in escapability analysis
2 parents e5ed233 + c8f8e86 commit 91b4fab

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
@@ -5350,6 +5350,14 @@ ClangTypeEscapability::evaluate(Evaluator &evaluator,
53505350
ClangTypeEscapability({elemTy, desc.impl, desc.annotationOnly}),
53515351
CxxEscapability::Unknown);
53525352
}
5353+
if (const auto *vecTy = desugared->getAs<clang::VectorType>()) {
5354+
return evaluateOrDefault(
5355+
evaluator,
5356+
ClangTypeEscapability(
5357+
{vecTy->getElementType()->getUnqualifiedDesugaredType(), desc.impl,
5358+
desc.annotationOnly}),
5359+
CxxEscapability::Unknown);
5360+
}
53535361

53545362
// Base cases
53555363
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)