Skip to content

Commit 60e8c8d

Browse files
authored
Merge pull request #34995 from zoecarver/tests/witness-table-opts
[nfc] Add tests for witness table size optimizations.
2 parents 36b589d + ec2e130 commit 60e8c8d

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

test/Interop/Cxx/value-witness-table/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ module CustomDestructor {
22
header "custom-destructors.h"
33
requires cplusplus
44
}
5+
6+
module WitnessLayoutOpts {
7+
header "witness-layout-opts.h"
8+
requires cplusplus
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H
2+
#define TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H
3+
4+
struct Empty { };
5+
6+
struct I8Size { char value; };
7+
8+
struct I32Size { char value[3]; char other; };
9+
10+
#endif // TEST_INTEROP_CXX_VALUE_WITNESS_TABLE_INPUTS_WITNESS_LAYOUT_H
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
2+
3+
// This test checks that the compiler uses well-known witness tables for types
4+
// that have the appropriate size/shape (for example, { i8 x 4 } -> i32).
5+
6+
// These witness tables look very differnt on Windows so it doesn't make sense
7+
// to test them in the same file.
8+
// XFAIL: OS=windows-msvc
9+
10+
import WitnessLayoutOpts
11+
12+
protocol Dummy { }
13+
14+
// CHECK-DAG: @"$sBi8_WV" = external global i8*, align 8
15+
// CHECK-DAG: @"$sSo5EmptyVMf" = linkonce_odr hidden constant {{.*}}@"$sBi8_WV"
16+
17+
extension Empty : Dummy { }
18+
19+
// CHECK-DAG: @"$sSo6I8SizeVMf" = linkonce_odr hidden constant {{.*}}@"$sBi8_WV"
20+
extension I8Size : Dummy { }
21+
22+
// CHECK-DAG: @"$sSo7I32SizeVWV" = linkonce_odr hidden constant %swift.vwtable { {{.*}} i8* bitcast (i32 (%swift.opaque*, i32, %swift.type*)* @"$sSo7I32SizeVwet" to i8*), i8* bitcast (void (%swift.opaque*, i32, i32, %swift.type*)* @"$sSo7I32SizeVwst" to i8*)
23+
// CHECK-DAG: "$sSo7I32SizeVMf" = linkonce_odr hidden constant {{.*}}@"$sSo7I32SizeVWV"
24+
extension I32Size : Dummy { }

0 commit comments

Comments
 (0)