Skip to content

Commit 395fe82

Browse files
committed
[move-only] Avoid loc from func decl.
It's always the first line of the function, so try to do better.
1 parent 33de9fa commit 395fe82

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyDiagnostics.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "swift/AST/DiagnosticsSIL.h"
1818
#include "swift/AST/Stmt.h"
19+
#include "swift/AST/Decl.h"
1920
#include "swift/Basic/Defer.h"
2021
#include "swift/SIL/BasicBlockBits.h"
2122
#include "swift/SIL/BasicBlockDatastructures.h"
@@ -226,6 +227,12 @@ void DiagnosticEmitter::emitMissingConsumeInDiscardingContext(
226227
return true;
227228

228229
case SILLocation::RegularKind: {
230+
Decl *decl = loc.getAsASTNode<Decl>();
231+
if (decl && isa<AbstractFunctionDecl>(decl)) {
232+
// Having the function itself as a location results in a location at the
233+
// first line of the function. Find another location.
234+
return false;
235+
}
229236
Stmt *stmt = loc.getAsASTNode<Stmt>();
230237
if (!stmt)
231238
return true; // For non-statements, assume it is exiting the func.

0 commit comments

Comments
 (0)