Skip to content

Commit c8e18d4

Browse files
committed
AST: use a static allocated NullLocs to indicate no serialized source locations for a Decl, NFC
1 parent 76f2695 commit c8e18d4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ class alignas(1 << DeclAlignInBits) Decl {
672672
SourceLoc StartLoc;
673673
SourceLoc EndLoc;
674674
};
675-
mutable CachedExternalSourceLocs *CachedLocs = nullptr;
676-
CachedExternalSourceLocs *calculateSerializedLocs() const;
675+
mutable CachedExternalSourceLocs const *CachedLocs = nullptr;
676+
const CachedExternalSourceLocs *calculateSerializedLocs() const;
677677
protected:
678678

679679
Decl(DeclKind kind, llvm::PointerUnion<DeclContext *, ASTContext *> context)

lib/AST/Decl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ case DeclKind::ID: return cast<ID##Decl>(this)->getLocFromSource();
486486
llvm_unreachable("Unknown decl kind");
487487
}
488488

489-
Decl::CachedExternalSourceLocs*
490-
Decl::calculateSerializedLocs() const {
491-
auto *Result = getASTContext().Allocate<Decl::CachedExternalSourceLocs>();
489+
const Decl::CachedExternalSourceLocs *Decl::calculateSerializedLocs() const {
492490
auto *File = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
493491
auto Locs = File->getBasicLocsForDecl(this);
494492
if (!Locs.hasValue()) {
495-
return Result;
493+
static const Decl::CachedExternalSourceLocs NullLocs;
494+
return &NullLocs;
496495
}
496+
auto *Result = getASTContext().Allocate<Decl::CachedExternalSourceLocs>();
497497
auto &SM = getASTContext().SourceMgr;
498498
#define CASE(X) \
499499
Result->X = SM.getLocFromExternalSource(Locs->SourceFilePath, Locs->X.Line, \

0 commit comments

Comments
 (0)