[move-only] Avoid loc from func decl.

It's always the first line of the function, so try to do better.
This commit is contained in:
Nate Chandler
2023-06-16 18:36:56 -07:00
parent eaf4560cd7
commit 11443f26ed
2 changed files with 15 additions and 8 deletions

View File

@@ -14,6 +14,7 @@
#include "MoveOnlyDiagnostics.h"
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsSIL.h"
#include "swift/AST/Stmt.h"
#include "swift/Basic/Defer.h"
@@ -226,6 +227,12 @@ void DiagnosticEmitter::emitMissingConsumeInDiscardingContext(
return true;
case SILLocation::RegularKind: {
Decl *decl = loc.getAsASTNode<Decl>();
if (decl && isa<AbstractFunctionDecl>(decl)) {
// Having the function itself as a location results in a location at the
// first line of the function. Find another location.
return false;
}
Stmt *stmt = loc.getAsASTNode<Stmt>();
if (!stmt)
return true; // For non-statements, assume it is exiting the func.