File tree Expand file tree Collapse file tree 5 files changed +47
-8
lines changed Expand file tree Collapse file tree 5 files changed +47
-8
lines changed Original file line number Diff line number Diff line change @@ -4297,6 +4297,12 @@ class StructDecl final : public NominalTypeDecl {
4297
4297
Bits.StructDecl .HasUnreferenceableStorage = v;
4298
4298
}
4299
4299
4300
+ // / Does this struct represent a non-trivial (for the purpose of calls, as
4301
+ // / defined by Itanium ABI) C++ record. A C++ record is considered non-trivial
4302
+ // / for the purpose of calls if either its constructor, copy-constructor, or
4303
+ // / destructor is non-trivial. As such, a C++ record with a non-trivial
4304
+ // / copy-assignment operator but other trivial members is considered to be
4305
+ // / trivial.
4300
4306
bool isCxxNonTrivial () const { return Bits.StructDecl .IsCxxNonTrivial ; }
4301
4307
4302
4308
void setIsCxxNonTrivial (bool v) { Bits.StructDecl .IsCxxNonTrivial = v; }
Original file line number Diff line number Diff line change @@ -2394,9 +2394,15 @@ namespace {
2394
2394
}
2395
2395
2396
2396
if (cxxRecordDecl) {
2397
+ auto isNonTrivialForPurposeOfCalls =
2398
+ [](const clang::CXXRecordDecl *decl) -> bool {
2399
+ return decl->hasNonTrivialCopyConstructor () ||
2400
+ decl->hasNonTrivialMoveConstructor () ||
2401
+ !decl->hasTrivialDestructor ();
2402
+ };
2397
2403
if (auto structResult = dyn_cast<StructDecl>(result))
2398
2404
structResult->setIsCxxNonTrivial (
2399
- !cxxRecordDecl-> isTriviallyCopyable ( ));
2405
+ isNonTrivialForPurposeOfCalls (cxxRecordDecl ));
2400
2406
2401
2407
for (auto &getterAndSetter : Impl.GetterSetterMap ) {
2402
2408
auto getter = getterAndSetter.second .first ;
Original file line number Diff line number Diff line change @@ -54,17 +54,17 @@ func pass(s: StructWithSubobjectDefaultedCopyConstructor) {
54
54
55
55
// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithCopyAssignment)
56
56
func pass( s: StructWithCopyAssignment ) {
57
- // CHECK: bb0(%0 : $* StructWithCopyAssignment):
57
+ // CHECK: bb0(%0 : $StructWithCopyAssignment):
58
58
}
59
59
60
60
// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithInheritedCopyAssignment)
61
61
func pass( s: StructWithInheritedCopyAssignment ) {
62
- // CHECK: bb0(%0 : $* StructWithInheritedCopyAssignment):
62
+ // CHECK: bb0(%0 : $StructWithInheritedCopyAssignment):
63
63
}
64
64
65
65
// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithSubobjectCopyAssignment)
66
66
func pass( s: StructWithSubobjectCopyAssignment ) {
67
- // CHECK: bb0(%0 : $* StructWithSubobjectCopyAssignment):
67
+ // CHECK: bb0(%0 : $StructWithSubobjectCopyAssignment):
68
68
}
69
69
70
70
// CHECK-LABEL: sil hidden [ossa] @$s4main4pass{{.*[ (]}}StructWithDestructor)
Original file line number Diff line number Diff line change 4
4
5
5
using PairInts = std::pair<int , int >;
6
6
7
- // FIXME: return pair by value, but it causes IRGen crash atm.
8
- inline const PairInts &getIntPair () {
9
- static PairInts value = { -5 , 12 };
7
+ inline const PairInts &getIntPairPointer () {
8
+ static PairInts value = { 4 , 9 };
10
9
return value;
11
10
}
11
+
12
+ inline PairInts getIntPair () {
13
+ return { -5 , 12 };
14
+ }
15
+
16
+ struct StructInPair {
17
+ int x;
18
+ int y;
19
+ };
20
+
21
+ using PairStructInt = std::pair<StructInPair, int >;
22
+
23
+ inline PairStructInt getPairStructInt (int x) {
24
+ return { { x * 2 , -x}, x };
25
+ }
Original file line number Diff line number Diff line change @@ -12,12 +12,25 @@ import Cxx
12
12
var StdPairTestSuite = TestSuite ( " StdPair " )
13
13
14
14
StdPairTestSuite . test ( " StdPair.elements " ) {
15
- var pi = getIntPair ( ) . pointee
15
+ var pi = getIntPair ( )
16
16
expectEqual ( pi. first, - 5 )
17
17
expectEqual ( pi. second, 12 )
18
18
pi. first = 11
19
19
expectEqual ( pi. first, 11 )
20
20
expectEqual ( pi. second, 12 )
21
21
}
22
22
23
+ StdPairTestSuite . test ( " StdPair.ref.elements " ) {
24
+ let pi = getIntPairPointer ( ) . pointee
25
+ expectEqual ( pi. first, 4 )
26
+ expectEqual ( pi. second, 9 )
27
+ }
28
+
29
+ StdPairTestSuite . test ( " PairStructInt.elements " ) {
30
+ let pair = getPairStructInt ( 11 )
31
+ expectEqual ( pair. first. x, 22 )
32
+ expectEqual ( pair. first. y, - 11 )
33
+ expectEqual ( pair. second, 11 )
34
+ }
35
+
23
36
runAllTests ( )
You can’t perform that action at this time.
0 commit comments