Skip to content

Commit 7e8d8b6

Browse files
authored
Merge pull request #85097 from meg-gupta/withdiagpr
Update borrow accessor diagnostics and synthesis
2 parents 77db003 + a71dbc6 commit 7e8d8b6

File tree

8 files changed

+594
-55
lines changed

8 files changed

+594
-55
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,9 +1798,16 @@ ERROR(mutating_invalid_classes,none, "%0 is not valid on %kindonly1s in "
17981798
ERROR(functions_mutating_and_not,none,
17991799
"method must not be declared both %0 and %1",
18001800
(SelfAccessKind, SelfAccessKind))
1801+
18011802
ERROR(static_functions_not_mutating,none,
18021803
"static functions must not be declared mutating", ())
18031804

1805+
ERROR(consuming_invalid_borrow_mutate_accessor, none,
1806+
"%0 cannot be declared consuming", (StringRef))
1807+
1808+
ERROR(ownership_modifier_unsupported_borrow_mutate_accessor, none,
1809+
"%0 ownership modifier is not yet supported on %1", (StringRef, StringRef))
1810+
18041811
ERROR(readwriter_mutatingness_differs_from_reader_or_writer_mutatingness,none,
18051812
"%0 cannot be %1 when "
18061813
"%select{both the %3 is %4 and the %5 is not %6|either the %3 is not %4 or the %5 is %6|the %3 is not %4|the %5 is %6}2",

lib/AST/Decl.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,6 +3264,10 @@ static AccessStrategy getOpaqueReadAccessStrategy(
32643264
return AccessStrategy::getAccessor(AccessorKind::Read2, dispatch);
32653265
if (storage->requiresOpaqueReadCoroutine())
32663266
return AccessStrategy::getAccessor(AccessorKind::Read, dispatch);
3267+
3268+
if (storage->getParsedAccessor(AccessorKind::Borrow)) {
3269+
return AccessStrategy::getAccessor(AccessorKind::Borrow, dispatch);
3270+
}
32673271
return AccessStrategy::getAccessor(AccessorKind::Get, dispatch);
32683272
}
32693273

@@ -3435,11 +3439,6 @@ bool AbstractStorageDecl::requiresOpaqueSetter() const {
34353439
if (!supportsMutation()) {
34363440
return false;
34373441
}
3438-
3439-
// If a mutate accessor is present, we don't need a setter.
3440-
if (getAccessor(AccessorKind::Mutate)) {
3441-
return false;
3442-
}
34433442
return true;
34443443
}
34453444

@@ -3450,7 +3449,7 @@ bool AbstractStorageDecl::requiresOpaqueReadCoroutine() const {
34503449
AccessorKind::Read2);
34513450

34523451
// If a borrow accessor is present, we don't need a read coroutine.
3453-
if (getAccessor(AccessorKind::Borrow)) {
3452+
if (getParsedAccessor(AccessorKind::Borrow)) {
34543453
return false;
34553454
}
34563455
return getOpaqueReadOwnership() != OpaqueReadOwnership::Owned;
@@ -3462,7 +3461,7 @@ bool AbstractStorageDecl::requiresOpaqueRead2Coroutine() const {
34623461
return false;
34633462

34643463
// If a borrow accessor is present, we don't need a read coroutine.
3465-
if (getAccessor(AccessorKind::Borrow)) {
3464+
if (getParsedAccessor(AccessorKind::Borrow)) {
34663465
return false;
34673466
}
34683467
return getOpaqueReadOwnership() != OpaqueReadOwnership::Owned;
@@ -7595,7 +7594,7 @@ StringRef swift::getAccessorNameForDiagnostic(AccessorKind accessorKind,
75957594
case AccessorKind::Init:
75967595
return article ? "an init accessor" : "init accessor";
75977596
case AccessorKind::Borrow:
7598-
return article ? " a 'borrow' accessor" : "borrow accessor";
7597+
return article ? "a 'borrow' accessor" : "borrow accessor";
75997598
case AccessorKind::Mutate:
76007599
return article ? "a 'mutate' accessor" : "mutate accessor";
76017600
}

lib/Sema/TypeCheckAttr.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,31 @@ void AttributeChecker::visitMutationAttr(DeclAttribute *attr) {
708708
// Verify that we don't have a static function.
709709
if (FD->isStatic())
710710
diagnoseAndRemoveAttr(attr, diag::static_functions_not_mutating);
711+
712+
auto *accessor = dyn_cast<AccessorDecl>(FD);
713+
if (accessor &&
714+
(accessor->isBorrowAccessor() || accessor->isMutateAccessor())) {
715+
if (attrModifier == SelfAccessKind::Consuming ||
716+
attrModifier == SelfAccessKind::LegacyConsuming) {
717+
diagnoseAndRemoveAttr(
718+
attr, diag::consuming_invalid_borrow_mutate_accessor,
719+
getAccessorNameForDiagnostic(accessor, /*article*/ true));
720+
}
721+
if (attrModifier == SelfAccessKind::NonMutating &&
722+
accessor->isMutateAccessor()) {
723+
diagnoseAndRemoveAttr(
724+
attr, diag::ownership_modifier_unsupported_borrow_mutate_accessor,
725+
attr->getAttrName(),
726+
getAccessorNameForDiagnostic(accessor, /*article*/ true));
727+
}
728+
if (attrModifier == SelfAccessKind::Mutating &&
729+
accessor->isBorrowAccessor()) {
730+
diagnoseAndRemoveAttr(
731+
attr, diag::ownership_modifier_unsupported_borrow_mutate_accessor,
732+
attr->getAttrName(),
733+
getAccessorNameForDiagnostic(accessor, /*article*/ true));
734+
}
735+
}
711736
}
712737

713738
void AttributeChecker::visitDynamicAttr(DynamicAttr *attr) {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,13 @@ synthesizeModify2CoroutineSetterBody(AccessorDecl *setter, ASTContext &ctx) {
18751875
setter, TargetImpl::Implementation, setter->getStorage(), ctx);
18761876
}
18771877

1878+
static std::pair<BraceStmt *, bool>
1879+
synthesizeMutateSetterBody(AccessorDecl *setter, ASTContext &ctx) {
1880+
// This should call the mutate accessor.
1881+
return synthesizeTrivialSetterBodyWithStorage(
1882+
setter, TargetImpl::Implementation, setter->getStorage(), ctx);
1883+
}
1884+
18781885
static Expr *maybeWrapInOutExpr(Expr *expr, ASTContext &ctx) {
18791886
if (auto lvalueType = expr->getType()->getAs<LValueType>()) {
18801887
auto type = lvalueType->getObjectType();
@@ -2071,7 +2078,7 @@ synthesizeSetterBody(AccessorDecl *setter, ASTContext &ctx) {
20712078
return synthesizeModify2CoroutineSetterBody(setter, ctx);
20722079

20732080
case WriteImplKind::Mutate:
2074-
llvm_unreachable("synthesizing setter from mutate");
2081+
return synthesizeMutateSetterBody(setter, ctx);
20752082
}
20762083
llvm_unreachable("bad WriteImplKind");
20772084
}
@@ -2476,7 +2483,9 @@ static AccessorDecl *createSetterPrototype(AbstractStorageDecl *storage,
24762483
}
24772484
break;
24782485
case WriteImplKind::Mutate:
2479-
llvm_unreachable("mutate accessor is not yet implemented");
2486+
if (auto mutate = storage->getOpaqueAccessor(AccessorKind::Mutate)) {
2487+
asAvailableAs.push_back(mutate);
2488+
}
24802489
}
24812490

24822491
if (!asAvailableAs.empty()) {
@@ -2804,11 +2813,6 @@ bool RequiresOpaqueModifyCoroutineRequest::evaluate(
28042813
if (protoDecl->isObjC())
28052814
return false;
28062815

2807-
// If a mutate accessor is present, we don't need a modify coroutine
2808-
if (storage->getAccessor(AccessorKind::Mutate)) {
2809-
return false;
2810-
}
2811-
28122816
return true;
28132817
}
28142818

@@ -2937,9 +2941,8 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
29372941
case WriteImplKind::MutableAddress:
29382942
case WriteImplKind::Modify:
29392943
case WriteImplKind::Modify2:
2940-
break;
29412944
case WriteImplKind::Mutate:
2942-
llvm_unreachable("mutate accessor is not yet implemented");
2945+
break;
29432946
}
29442947
break;
29452948

@@ -2950,14 +2953,12 @@ IsAccessorTransparentRequest::evaluate(Evaluator &evaluator,
29502953
case AccessorKind::Init:
29512954
break;
29522955
case AccessorKind::Borrow:
2953-
llvm_unreachable("borrow accessor is not yet implemented");
29542956
case AccessorKind::WillSet:
29552957
case AccessorKind::DidSet:
29562958
case AccessorKind::Address:
29572959
case AccessorKind::MutableAddress:
2958-
llvm_unreachable("bad synthesized function kind");
29592960
case AccessorKind::Mutate:
2960-
llvm_unreachable("mutate accessor is not yet implemented");
2961+
llvm_unreachable("bad synthesized function kind");
29612962
}
29622963

29632964
switch (storage->getReadWriteImpl()) {

test/IRGen/borrow_accessor_large.swift

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -c %s -Xllvm -sil-print-after=loadable-address -enable-experimental-feature BorrowAndMutateAccessors 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-irgen %s -enable-experimental-feature BorrowAndMutateAccessors 2>&1 | %FileCheck --check-prefixes=CHECK-IRGEN %s
23

34
// REQUIRES: swift_feature_BorrowAndMutateAccessors
45
// REQUIRES: OS=macosx
@@ -137,9 +138,9 @@ func nctest() {
137138
// CHECK: }
138139

139140
// IRGen result type is PtrTy because we are returning a class reference
140-
// CHECK-IRGEN: define hidden swiftcc ptr @"$s21borrow_accessor_large11LargeStructV0A5KlassAA0F0Cvb"(ptr noalias nocapture swiftself dereferenceable(208) [[REG0]]) {{.*}} {
141+
// CHECK-IRGEN: define hidden swiftcc ptr @"$s21borrow_accessor_large11LargeStructV0A5KlassAA0F0Cvb"(ptr noalias swiftself captures(none) dereferenceable(208) [[REG0:%.*]]) {{.*}} {
141142
// CHECK-IRGEN: entry:
142-
// CHECK-IRGEN: %._k = getelementptr inbounds %T21borrow_accessor_large11LargeStructV, ptr [[REG0]], i32 0, i32 0
143+
// CHECK-IRGEN: %._k = getelementptr inbounds nuw %T21borrow_accessor_large11LargeStructV, ptr [[REG0]], i32 0, i32 0
143144
// CHECK-IRGEN: [[REG1:%.*]] = load ptr, ptr %._k, align 8
144145
// CHECK-IRGEN: ret ptr [[REG1]]
145146
// CHECK-IRGEN: }
@@ -151,11 +152,11 @@ func nctest() {
151152
// CHECK: return [[REG3]]
152153
// CHECK: }
153154

154-
// CHECK-IRGEN: define hidden swiftcc i64 @"$s21borrow_accessor_large11LargeStructV0a5SmallE0AA0fE0Vvb"(ptr noalias nocapture swiftself dereferenceable(208) [[REG0]]) {{.*}} {
155+
// CHECK-IRGEN: define hidden swiftcc i64 @"$s21borrow_accessor_large11LargeStructV0a5SmallE0AA0fE0Vvb"(ptr noalias swiftself captures(none) dereferenceable(208) [[REG0:%.*]]) {{.*}} {
155156
// CHECK-IRGEN: entry:
156-
// CHECK-IRGEN: %._smallStruct = getelementptr inbounds %T21borrow_accessor_large11LargeStructV, ptr [[REG0]], i32 0, i32 4
157-
// CHECK-IRGEN: %._smallStruct.id = getelementptr inbounds %T21borrow_accessor_large11SmallStructV, ptr %._smallStruct, i32 0, i32 0
158-
// CHECK-IRGEN: %._smallStruct.id._value = getelementptr inbounds %TSi, ptr %._smallStruct.id, i32 0, i32 0
157+
// CHECK-IRGEN: %._smallStruct = getelementptr inbounds nuw %T21borrow_accessor_large11LargeStructV, ptr [[REG0]], i32 0, i32 4
158+
// CHECK-IRGEN: %._smallStruct.id = getelementptr inbounds nuw %T21borrow_accessor_large11SmallStructV, ptr %._smallStruct, i32 0, i32 0
159+
// CHECK-IRGEN: %._smallStruct.id._value = getelementptr inbounds nuw %TSi, ptr %._smallStruct.id, i32 0, i32 0
159160
// CHECK-IRGEN: [[REG1:%.*]] = load i64, ptr %._smallStruct.id._value, align 8
160161
// CHECK-IRGEN: ret i64 [[REG1]]
161162
// CHECK-IRGEN: }
@@ -169,9 +170,9 @@ func nctest() {
169170
// CHECK: return [[REG5]]
170171
// CHECK: }
171172

172-
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large11LargeStructV0C10PropBorrowAA0dF0Vvb"(ptr noalias nocapture sret(%T21borrow_accessor_large9LargePropV) [[REG0]], ptr noalias nocapture swiftself dereferenceable(208) [[REG1]]) {{.*}} {
173+
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large11LargeStructV0C10PropBorrowAA0dF0Vvb"(ptr noalias sret(%T21borrow_accessor_large9LargePropV) captures(none) [[REG0:%.*]], ptr noalias swiftself captures(none) dereferenceable(208) [[REG1:%.*]]) {{.*}} {
173174
// CHECK-IRGEN: entry:
174-
// CHECK-IRGEN: %._largeProp = getelementptr inbounds %T21borrow_accessor_large11LargeStructV, ptr [[REG1]], i32 0, i32 3
175+
// CHECK-IRGEN: %._largeProp = getelementptr inbounds nuw %T21borrow_accessor_large11LargeStructV, ptr [[REG1]], i32 0, i32 3
175176
// CHECK-IRGEN: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[REG0]], ptr align 8 %._largeProp, i64 64, i1 false)
176177
// CHECK-IRGEN: ret void
177178
// CHECK-IRGEN: }
@@ -184,40 +185,40 @@ func nctest() {
184185
// CHECK: return [[REG3]]
185186
// CHECK: }
186187

187-
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large11LargeStructV0C11TupleBorrowAA5KlassC_A7Ftvb"(ptr noalias nocapture sret(<{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>) [[REG0]], ptr noalias nocapture swiftself dereferenceable(208) [[REG1]]) {{.*}} {
188+
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large11LargeStructV0C11TupleBorrowAA5KlassC_A7Ftvb"(ptr noalias sret(<{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>) captures(none) [[REG0:%.*]], ptr noalias swiftself captures(none) dereferenceable(208) [[REG1:%.*]]) {{.*}} {
188189
// CHECK-IRGEN: entry:
189-
// CHECK-IRGEN: %._largeTuple = getelementptr inbounds %T21borrow_accessor_large11LargeStructV, ptr [[REG1]], i32 0, i32 2
190-
// CHECK-IRGEN: %._largeTuple.elt = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 0
190+
// CHECK-IRGEN: %._largeTuple = getelementptr inbounds nuw %T21borrow_accessor_large11LargeStructV, ptr [[REG1]], i32 0, i32 2
191+
// CHECK-IRGEN: %._largeTuple.elt = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 0
191192
// CHECK-IRGEN: [[REG2:%.*]] = load ptr, ptr %._largeTuple.elt, align 8
192-
// CHECK-IRGEN: %._largeTuple.elt1 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 1
193+
// CHECK-IRGEN: %._largeTuple.elt1 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 1
193194
// CHECK-IRGEN: [[REG3:%.*]] = load ptr, ptr %._largeTuple.elt1, align 8
194-
// CHECK-IRGEN: %._largeTuple.elt2 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 2
195+
// CHECK-IRGEN: %._largeTuple.elt2 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 2
195196
// CHECK-IRGEN: [[REG4:%.*]] = load ptr, ptr %._largeTuple.elt2, align 8
196-
// CHECK-IRGEN: %._largeTuple.elt3 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 3
197+
// CHECK-IRGEN: %._largeTuple.elt3 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 3
197198
// CHECK-IRGEN: [[REG5:%.*]] = load ptr, ptr %._largeTuple.elt3, align 8
198-
// CHECK-IRGEN: %._largeTuple.elt4 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 4
199+
// CHECK-IRGEN: %._largeTuple.elt4 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 4
199200
// CHECK-IRGEN: [[REG6:%.*]] = load ptr, ptr %._largeTuple.elt4, align 8
200-
// CHECK-IRGEN: %._largeTuple.elt5 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 5
201+
// CHECK-IRGEN: %._largeTuple.elt5 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 5
201202
// CHECK-IRGEN: [[REG7:%.*]] = load ptr, ptr %._largeTuple.elt5, align 8
202-
// CHECK-IRGEN: %._largeTuple.elt6 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 6
203+
// CHECK-IRGEN: %._largeTuple.elt6 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 6
203204
// CHECK-IRGEN: [[REG8:%.*]] = load ptr, ptr %._largeTuple.elt6, align 8
204-
// CHECK-IRGEN: %._largeTuple.elt7 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 7
205+
// CHECK-IRGEN: %._largeTuple.elt7 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr %._largeTuple, i32 0, i32 7
205206
// CHECK-IRGEN: [[REG9:%.*]] = load ptr, ptr %._largeTuple.elt7, align 8
206-
// CHECK-IRGEN: %.elt = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 0
207+
// CHECK-IRGEN: %.elt = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 0
207208
// CHECK-IRGEN: store ptr [[REG2]], ptr %.elt, align 8
208-
// CHECK-IRGEN: %.elt8 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 1
209+
// CHECK-IRGEN: %.elt8 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 1
209210
// CHECK-IRGEN: store ptr [[REG3]], ptr %.elt8, align 8
210-
// CHECK-IRGEN: %.elt9 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 2
211+
// CHECK-IRGEN: %.elt9 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 2
211212
// CHECK-IRGEN: store ptr [[REG4]], ptr %.elt9, align 8
212-
// CHECK-IRGEN: %.elt10 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 3
213+
// CHECK-IRGEN: %.elt10 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 3
213214
// CHECK-IRGEN: store ptr [[REG5]], ptr %.elt10, align 8
214-
// CHECK-IRGEN: %.elt11 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 4
215+
// CHECK-IRGEN: %.elt11 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 4
215216
// CHECK-IRGEN: store ptr [[REG6]], ptr %.elt11, align 8
216-
// CHECK-IRGEN: %.elt12 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 5
217+
// CHECK-IRGEN: %.elt12 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 5
217218
// CHECK-IRGEN: store ptr [[REG7]], ptr %.elt12, align 8
218-
// CHECK-IRGEN: %.elt13 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 6
219+
// CHECK-IRGEN: %.elt13 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 6
219220
// CHECK-IRGEN: store ptr [[REG8]], ptr %.elt13, align 8
220-
// CHECK-IRGEN: %.elt14 = getelementptr inbounds <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 7
221+
// CHECK-IRGEN: %.elt14 = getelementptr inbounds nuw <{ ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>, ptr [[REG0]], i32 0, i32 7
221222
// CHECK-IRGEN: store ptr [[REG9]], ptr %.elt14, align 8
222223
// CHECK-IRGEN: ret void
223224
// CHECK-IRGEN: }
@@ -229,11 +230,11 @@ func nctest() {
229230
// CHECK: return [[REG3]]
230231
// CHECK: }
231232

232-
// CHECK-IRGEN: define hidden swiftcc i64 @"$s21borrow_accessor_large13NCLargeStructV0A2NCAA0F0Vvb"(ptr noalias nocapture swiftself dereferenceable(72) [[REG0]]) {{.*}} {
233+
// CHECK-IRGEN: define hidden swiftcc i64 @"$s21borrow_accessor_large13NCLargeStructV0A2NCAA0F0Vvb"(ptr noalias swiftself captures(none) dereferenceable(72) [[REG0:%.*]]) {{.*}} {
233234
// CHECK-IRGEN: entry:
234-
// CHECK-IRGEN: %._k = getelementptr inbounds %T21borrow_accessor_large13NCLargeStructV, ptr [[REG0]], i32 0, i32 0
235-
// CHECK-IRGEN: %._k.id = getelementptr inbounds %T21borrow_accessor_large2NCV, ptr %._k, i32 0, i32 0
236-
// CHECK-IRGEN: %._k.id._value = getelementptr inbounds %TSi, ptr %._k.id, i32 0, i32 0
235+
// CHECK-IRGEN: %._k = getelementptr inbounds nuw %T21borrow_accessor_large13NCLargeStructV, ptr [[REG0]], i32 0, i32 0
236+
// CHECK-IRGEN: %._k.id = getelementptr inbounds nuw %T21borrow_accessor_large2NCV, ptr %._k, i32 0, i32 0
237+
// CHECK-IRGEN: %._k.id._value = getelementptr inbounds nuw %TSi, ptr %._k.id, i32 0, i32 0
237238
// CHECK-IRGEN: [[REG1:%.*]] = load i64, ptr %._k.id._value, align 8
238239
// CHECK-IRGEN: ret i64 [[REG1]]
239240
// CHECK-IRGEN: }
@@ -247,9 +248,9 @@ func nctest() {
247248
// CHECK: return [[REG5]]
248249
// CHECK: }
249250

250-
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large13NCLargeStructV0C10PropBorrowAA11LargeNCPropVvb"(ptr noalias nocapture sret(%T21borrow_accessor_large11LargeNCPropV) [[REG0]], ptr noalias nocapture swiftself dereferenceable(72) [[REG1]]) {{.*}} {
251+
// CHECK-IRGEN: define hidden swiftcc void @"$s21borrow_accessor_large13NCLargeStructV0C10PropBorrowAA11LargeNCPropVvb"(ptr noalias sret(%T21borrow_accessor_large11LargeNCPropV) captures(none) [[REG0]], ptr noalias swiftself captures(none) dereferenceable(72) [[REG1:%.*]]) {{.*}} {
251252
// CHECK-IRGEN: entry:
252-
// CHECK-IRGEN: %._largeProp = getelementptr inbounds %T21borrow_accessor_large13NCLargeStructV, ptr [[REG1]], i32 0, i32 1
253+
// CHECK-IRGEN: %._largeProp = getelementptr inbounds nuw %T21borrow_accessor_large13NCLargeStructV, ptr [[REG1]], i32 0, i32 1
253254
// CHECK-IRGEN: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[REG0]], ptr align 8 %._largeProp, i64 64, i1 false)
254255
// CHECK-IRGEN: ret void
255256
// CHECK-IRGEN: }

test/Parse/borrow_and_mutate_accessors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ struct Wrapper {
1515
}
1616
}
1717
var k2: Klass {
18-
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a getter}}
18+
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a getter}}
1919
return _k
2020
}
2121
get { // expected-note{{getter defined here}}
2222
return _k
2323
}
2424
}
2525
var k3: Klass {
26-
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a '_read' accessor}}
26+
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a '_read' accessor}}
2727
return _k
2828
}
2929
_read { // expected-note{{'_read' accessor defined here}}
3030
yield _k
3131
}
3232
}
3333
var k4: Klass {
34-
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a 'read' accessor}}
34+
borrow { // expected-error{{variable cannot provide both a 'borrow' accessor and a 'read' accessor}}
3535
return _k
3636
}
3737
read { // expected-note{{'read' accessor defined here}}

0 commit comments

Comments
 (0)