Skip to content

Commit 57b8d6c

Browse files
committed
[SourceKit] Use "-" as fallback complier argument
Since compiler arguments are processed by Driver, arbitrary filename passed as 'request.name' (e.g. "", "-1", etc.) may cause problems. Using '-' guarantees successful initialization of 'CompilerInvocation'. rdar://problem/40646921 rdar://problem/40955808
1 parent c7d53f7 commit 57b8d6c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

test/SourceKit/DocumentStructure/structure.swift.placeholders.response

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
key.name: "<#MyCls#>",
1010
key.offset: 0,
1111
key.length: 35,
12-
key.runtime_name: "_TtC12placeholders9<#MyCls#>",
12+
key.runtime_name: "_TtC4main9<#MyCls#>",
1313
key.nameoffset: 6,
1414
key.namelength: 9,
1515
key.bodyoffset: 34,

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,8 +1757,11 @@ void SwiftEditorDocument::parse(ImmutableTextSnapshotRef Snapshot,
17571757
Impl.SemanticInfo->getInvocation()->applyTo(CompInv);
17581758
Impl.SemanticInfo->getInvocation()->raw(Args, PrimaryFile);
17591759
} else {
1760+
// Use stdin as a .swift input to satisfy the driver. Note that we don't
1761+
// use Impl.FilePath here because it may be invalid filename for driver
1762+
// like "" or "-foobar".
17601763
SmallVector<const char *, 1> Args;
1761-
Args.push_back(Impl.FilePath.c_str()); // Input
1764+
Args.push_back("-");
17621765
std::string Error;
17631766
// Ignore possible error(s)
17641767
Lang.getASTManager().

0 commit comments

Comments
 (0)