Skip to content

[DNM] [Basic] Assert same buffer in isBeforeInBuffer #80402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_BASIC_SOURCEMANAGER_H
#define SWIFT_BASIC_SOURCEMANAGER_H

#include "swift/Basic/Assertions.h"
#include "swift/Basic/FileSystem.h"
#include "swift/Basic/SourceLoc.h"
#include "clang/Basic/FileManager.h"
Expand Down Expand Up @@ -305,6 +306,8 @@ class SourceManager {

/// Returns true if \c LHS is before \c RHS in the same source buffer.
bool isBeforeInBuffer(SourceLoc LHS, SourceLoc RHS) const {
CONDITIONAL_ASSERT(findBufferContainingLoc(LHS) ==
findBufferContainingLoc(RHS));
return LHS.Value.getPointer() < RHS.Value.getPointer();
}

Expand Down
20 changes: 0 additions & 20 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,26 +966,6 @@ case DeclKind::ID: return cast<ID##Decl>(this)->getSourceRange();
SourceRange Decl::getSourceRangeIncludingAttrs() const {
auto Range = getSourceRange();

// Attributes on AccessorDecl may syntactically belong to PatternBindingDecl.
// e.g. 'override'.
if (auto *AD = dyn_cast<AccessorDecl>(this)) {
// If this is implicit getter, accessor range should not include attributes.
if (AD->isImplicitGetter())
return Range;

// Otherwise, include attributes directly attached to the accessor.
SourceLoc VarLoc = AD->getStorage()->getStartLoc();
for (auto *Attr : getParsedAttrs()) {
if (!Attr->getRange().isValid())
continue;

SourceLoc AttrStartLoc = Attr->getRangeWithAt().Start;
if (getASTContext().SourceMgr.isBeforeInBuffer(VarLoc, AttrStartLoc))
Range.widen(AttrStartLoc);
}
return Range;
}

// Attributes on VarDecl syntactically belong to PatternBindingDecl.
if (isa<VarDecl>(this) && !isa<ParamDecl>(this))
return Range;
Expand Down