Skip to content

Commit 635550c

Browse files
committed
[SymbolGraph] Check Loc validity before extracting text
Hit this crash while walking an `import protocol ...` declaration. Check loc validity before calling `SourceManager::extractText`: there is an assertion at the beginning of this function. rdar://65258208
1 parent c6cd4b0 commit 635550c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ bool SemaAnnotator::
684684
passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data) {
685685
SourceManager &SM = D->getASTContext().SourceMgr;
686686
SourceLoc BaseStart = Loc.getBaseNameLoc(), BaseEnd = BaseStart;
687-
if (SM.extractText({BaseStart, 1}) == "`")
687+
if (BaseStart.isValid() && SM.extractText({BaseStart, 1}) == "`")
688688
BaseEnd = Lexer::getLocForEndOfToken(SM, BaseStart.getAdvancedLoc(1));
689689
return passReference(D, Ty, BaseStart, {BaseStart, BaseEnd}, Data);
690690
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol P {
2+
func foo()
3+
}
Lines changed: 15 additions & 0 deletions
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)