Skip to content

Commit 55199f5

Browse files
Merge pull request #35919 from apple/QuietMisdreavus/invalid-range-raw-comment
don't load raw comments for invalid serialized ranges
2 parents a223d37 + a69813f commit 55199f5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/AST/RawComment.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
154154
if (!CachedLocs->DocRanges.empty()) {
155155
SmallVector<SingleRawComment, 4> SRCs;
156156
for (const auto &Range : CachedLocs->DocRanges) {
157-
SRCs.push_back({ Range, Context.SourceMgr });
157+
if (Range.isValid()) {
158+
SRCs.push_back({ Range, Context.SourceMgr });
159+
} else {
160+
// if we've run into an invalid range, don't bother trying to load any of
161+
// the other comments
162+
SRCs.clear();
163+
break;
164+
}
158165
}
159166
auto RC = RawComment(Context.AllocateCopy(llvm::makeArrayRef(SRCs)));
160167

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/Source)
3+
// RUN: %empty-directory(%t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule)
4+
// RUN: %empty-directory(%t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule/Project)
5+
6+
// RUN: cp %s %t/Source/Input.swift
7+
8+
// RUN: %target-swift-frontend -module-name NoSourceInfo -emit-module -emit-module-path %t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule/%target-swiftmodule-name -emit-module-doc-path %t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule/%target-swiftdoc-name -emit-module-interface-path %t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule/%target-swiftinterface-name -emit-module-source-info-path %t/NoSourceInfo.framework/Modules/NoSourceInfo.swiftmodule/Project/%target-swiftsourceinfo-name %t/Source/Input.swift
9+
10+
// RUN: mv %t/Source %t/MovedSource
11+
12+
// RUN: %target-swift-symbolgraph-extract -module-name NoSourceInfo -F %t -pretty-print -output-dir %t
13+
// RUN: %FileCheck %s --input-file %t/NoSourceInfo.symbols.json
14+
15+
// CHECK: s:12NoSourceInfo1SV
16+
// CHECK: docComment
17+
// CHECK: This is a test
18+
19+
/// This is a test
20+
public struct S {
21+
/// This is also a test
22+
public var x: Int
23+
}
24+
25+
/// writing some docs here
26+
open class C<Data> {
27+
/// writing more docs over there
28+
public init() {}
29+
}
30+
31+
open class CO: C<String> {
32+
override public init() { super.init() }
33+
}

0 commit comments

Comments
 (0)