File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -636,9 +636,18 @@ const ExternalSourceLocs *Decl::getSerializedLocs() const {
636
636
return &NullLocs;
637
637
}
638
638
639
+ CharSourceRange BufferRange = SM.getRangeForBuffer (BufferID);
639
640
auto ResolveLoc = [&](const ExternalSourceLocs::RawLoc &Raw) -> SourceLoc {
641
+ // If the underlying source has been updated and the swiftsourceinfo hasn't,
642
+ // make sure we don't produce invalid source locations. Ideally would check
643
+ // the file hasn't been modified.
644
+ if (Raw.Offset > BufferRange.getByteLength ())
645
+ return SourceLoc ();
646
+
640
647
// If the decl had a presumed loc, create its virtual file so that
641
- // getPresumedLineAndColForLoc works from serialized locations as well.
648
+ // getPresumedLineAndColForLoc works from serialized locations as well. No
649
+ // need to check the buffer range, the directive must be before the location
650
+ // itself.
642
651
if (Raw.Directive .isValid ()) {
643
652
auto &LD = Raw.Directive ;
644
653
SourceLoc Loc = SM.getLocForOffset (BufferID, LD.Offset );
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ open class SubClass: ParentClass {
59
59
// CHECK-OUTOFDATE-NOT: moda.ParentClass:{{.*}}: note:
60
60
// CHECK-OUTOFDATE: moda.swift:{{.*}}: note:
61
61
62
+ // Underlying file is empty, the locations are now completely invalid (ie. not
63
+ // within the buffer). Make sure there's no crash and that we fallback to using
64
+ // the generated source.
65
+ // RUN: rm %t/moda.swift
66
+ // RUN: touch %t/moda.swift
67
+ // RUN: not %target-swift-frontend -typecheck -I %t/mods -D MODB %s 2>&1 | %FileCheck -check-prefix=CHECK-EMPTY %s
68
+ // CHECK-EMPTY: moda.ParentClass:{{.*}}: note:
69
+
62
70
// The file and line from a location directive should be used whether or not it
63
71
// exists - the actual source still comes from the original file, so that's what
64
72
// matters in terms of whether generated code is used or not
You can’t perform that action at this time.
0 commit comments