Skip to content

Commit 05c3333

Browse files
authored
Merge pull request #33370 from bitjammer/acgarland/rdar-65258208-crash-invalid-loc-extracttext
[SymbolGraph] Check Loc validity before extracting text
2 parents d8bef6e + 635550c commit 05c3333

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Diff for: lib/IDE/SourceEntityWalker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ bool SemaAnnotator::
685685
passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data) {
686686
SourceManager &SM = D->getASTContext().SourceMgr;
687687
SourceLoc BaseStart = Loc.getBaseNameLoc(), BaseEnd = BaseStart;
688-
if (SM.extractText({BaseStart, 1}) == "`")
688+
if (BaseStart.isValid() && SM.extractText({BaseStart, 1}) == "`")
689689
BaseEnd = Lexer::getLocForEndOfToken(SM, BaseStart.getAdvancedLoc(1));
690690
return passReference(D, Ty, BaseStart, {BaseStart, BaseEnd}, Data);
691691
}

Diff for: test/SymbolGraph/Something/Inputs/SomeProtocol.swift

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol P {
2+
func foo()
3+
}

Diff for: test/SymbolGraph/Something/Something.swift

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %S/Inputs/SomeProtocol.swift -module-name SomeProtocol -emit-module -emit-module-path %t/
3+
// RUN: %target-build-swift %s -module-name Something -emit-module -emit-module-path %t/ -I %t
4+
// RUN: %target-swift-symbolgraph-extract -module-name Something -I %t -pretty-print -output-dir %t
5+
// RUN: %FileCheck %s --input-file %t/Something.symbols.json
6+
7+
import protocol SomeProtocol.P
8+
9+
public struct MyStruct: P {
10+
public func foo() {}
11+
}
12+
13+
// CHECK: "kind": "conformsTo",
14+
// CHECK-NEXT: "source": "s:9Something8MyStructV",
15+
// CHECK-NEXT: "target": "s:12SomeProtocol1PP",

0 commit comments

Comments
 (0)