Skip to content

Commit 9ac56f2

Browse files
authored
Merge pull request #76249 from swiftlang/egorzhdan/simd-template-param
[cxx-interop] Disambiguate template instantiations with SIMD parameters
2 parents be9d344 + d19c9eb commit 9ac56f2

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

lib/ClangImporter/ClangClassTemplateNamePrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ struct TemplateInstantiationNamePrinter
129129

130130
return buffer.str().str();
131131
}
132+
133+
std::string VisitVectorType(const clang::VectorType *type) {
134+
return (Twine("SIMD") + std::to_string(type->getNumElements()) + "<" +
135+
Visit(type->getElementType().getTypePtr()) + ">")
136+
.str();
137+
}
132138
};
133139

134140
std::string swift::importer::printClassTemplateSpecializationName(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <simd/simd.h>
2+
3+
template <typename T>
4+
struct Templated {
5+
T t;
6+
};
7+
8+
typedef Templated<simd::uint1> TemplatedSIMDUInt1;
9+
typedef Templated<simd::uint16> TemplatedSIMDUInt16;
10+
typedef Templated<simd::float3> TemplatedSIMDFloat3;
11+
typedef Templated<simd::float4> TemplatedSIMDFloat4;
12+
typedef Templated<simd::double8> TemplatedSIMDDouble8;

test/Interop/Cxx/templates/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ module ClassTemplateWithOutOfLineMember {
1818
requires cplusplus
1919
}
2020

21+
module ClassTemplateWithSIMDParameter {
22+
header "class-template-with-simd-parameter.h"
23+
requires cplusplus
24+
}
25+
2126
module NotPreDefinedClassTemplate {
2227
header "not-pre-defined-class-template.h"
2328
requires cplusplus
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=ClassTemplateWithSIMDParameter -I %S/Inputs -source-filename=x -cxx-interoperability-mode=upcoming-swift | %FileCheck %s
2+
3+
// REQUIRES: OS=macosx || OS=ios
4+
5+
// CHECK: typealias TemplatedSIMDUInt1 = Templated<CUnsignedInt>
6+
// CHECK: typealias TemplatedSIMDUInt16 = Templated<SIMD16<CUnsignedInt>>
7+
// CHECK: typealias TemplatedSIMDFloat3 = Templated<SIMD3<CFloat>>
8+
// CHECK: typealias TemplatedSIMDFloat4 = Templated<SIMD4<CFloat>>
9+
// CHECK: typealias TemplatedSIMDDouble8 = Templated<SIMD8<CDouble>>

0 commit comments

Comments
 (0)