Skip to content

Commit 68748a8

Browse files
committed
Merge remote-tracking branch 'origin/main' into next
2 parents 053894c + 89418c6 commit 68748a8

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

lib/SIL/Verifier/MemoryLifetimeVerifier.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ static bool isTrivialEnumElem(EnumElementDecl *elem, SILType enumType,
178178
enumType.getEnumElementType(elem, function).isTrivial(*function);
179179
}
180180

181+
static bool isOrHasEnum(SILType type) {
182+
return type.getASTType().findIf([](Type ty) {
183+
return ty->getEnumOrBoundGenericEnum() != nullptr;
184+
});
185+
}
186+
181187
bool MemoryLifetimeVerifier::storesTrivialEnum(int locIdx,
182188
SILBasicBlock::reverse_iterator start,
183189
SILBasicBlock::reverse_iterator end) {
@@ -191,7 +197,7 @@ bool MemoryLifetimeVerifier::storesTrivialEnum(int locIdx,
191197
if (auto *SI = dyn_cast<StoreInst>(&inst)) {
192198
const Location *loc = locations.getLocation(SI->getDest());
193199
if (loc && loc->isSubLocation(locIdx) &&
194-
SI->getSrc()->getType().getEnumOrBoundGenericEnum()) {
200+
isOrHasEnum(SI->getSrc()->getType())) {
195201
return SI->getOwnershipQualifier() == StoreOwnershipQualifier::Trivial;
196202
}
197203
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,8 +5343,17 @@ bool ExtraneousReturnFailure::diagnoseAsError() {
53435343
if (FD->getResultTypeRepr() == nullptr &&
53445344
FD->getParameters()->getStartLoc().isValid() &&
53455345
!FD->getBaseIdentifier().empty()) {
5346-
auto fixItLoc = Lexer::getLocForEndOfToken(
5347-
getASTContext().SourceMgr, FD->getParameters()->getEndLoc());
5346+
// Insert the fix-it after the parameter list, and after any
5347+
// effects specifiers.
5348+
SourceLoc loc = FD->getParameters()->getEndLoc();
5349+
if (auto asyncLoc = FD->getAsyncLoc())
5350+
loc = asyncLoc;
5351+
5352+
if (auto throwsLoc = FD->getThrowsLoc())
5353+
if (throwsLoc.getOpaquePointerValue() > loc.getOpaquePointerValue())
5354+
loc = throwsLoc;
5355+
5356+
auto fixItLoc = Lexer::getLocForEndOfToken(getASTContext().SourceMgr, loc);
53485357
emitDiagnostic(diag::add_return_type_note)
53495358
.fixItInsert(fixItLoc, " -> <#Return Type#>");
53505359
}

test/Constraints/diagnostics.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,43 @@ func voidFuncWithNestedVoidFunc() {
12131213
}
12141214
}
12151215

1216+
func voidFuncWithEffects1() throws {
1217+
return 1
1218+
// expected-error@-1 {{unexpected non-void return value in void function}}
1219+
// expected-note@-2 {{did you mean to add a return type?}}{{35-35= -> <#Return Type#>}}
1220+
}
1221+
1222+
func voidFuncWithEffects2() async throws {
1223+
return 1
1224+
// expected-error@-1 {{unexpected non-void return value in void function}}
1225+
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1226+
}
1227+
1228+
// expected-error@+1 {{'async' must precede 'throws'}}
1229+
func voidFuncWithEffects3() throws async {
1230+
return 1
1231+
// expected-error@-1 {{unexpected non-void return value in void function}}
1232+
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1233+
}
1234+
1235+
func voidFuncWithEffects4() async {
1236+
return 1
1237+
// expected-error@-1 {{unexpected non-void return value in void function}}
1238+
// expected-note@-2 {{did you mean to add a return type?}}{{34-34= -> <#Return Type#>}}
1239+
}
1240+
1241+
func voidFuncWithEffects5(_ closure: () throws -> Void) rethrows {
1242+
return 1
1243+
// expected-error@-1 {{unexpected non-void return value in void function}}
1244+
// expected-note@-2 {{did you mean to add a return type?}}{{65-65= -> <#Return Type#>}}
1245+
}
1246+
1247+
func voidGenericFuncWithEffects<T>(arg: T) async where T: CustomStringConvertible {
1248+
return 1
1249+
// expected-error@-1 {{unexpected non-void return value in void function}}
1250+
// expected-note@-2 {{did you mean to add a return type?}}{{49-49= -> <#Return Type#>}}
1251+
}
1252+
12161253
// Special cases: These should not offer a note + fix-it
12171254

12181255
func voidFuncExplicitType() -> Void {

test/SIL/memory_lifetime.sil

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ bb0(%0 : @owned $T):
464464
return %r : $()
465465
}
466466

467+
sil [ossa] @test_store_enum_tuple : $@convention(thin) (Int) -> () {
468+
bb0(%0 : $Int):
469+
%2 = enum $Optional<T>, #Optional.none!enumelt
470+
%3 = tuple (%0 : $Int, %2 : $Optional<T>)
471+
%8 = alloc_stack $(Int, Optional<T>)
472+
store %3 to [trivial] %8 : $*(Int, Optional<T>)
473+
dealloc_stack %8 : $*(Int, Optional<T>)
474+
%13 = tuple ()
475+
return %13 : $()
476+
}
477+
467478
sil [ossa] @test_select_enum_addr : $@convention(thin) (@in_guaranteed Optional<T>) -> Builtin.Int1 {
468479
bb0(%0 : $*Optional<T>):
469480
%1 = integer_literal $Builtin.Int1, -1

0 commit comments

Comments
 (0)