Skip to content

Commit ee919ae

Browse files
authored
Merge pull request #71782 from ahoppen/ahoppen/incomplete-output-file-map
[Driver] Don’t crash if the output file map is incomplete
2 parents 056c22f + a49994d commit ee919ae

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Basic/OutputFileMap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ OutputFileMap::parse(std::unique_ptr<llvm::MemoryBuffer> Buffer,
209209
llvm::yaml::Node *Key = OutputPair.getKey();
210210
llvm::yaml::Node *Value = OutputPair.getValue();
211211

212+
if (!Key)
213+
return constructError("bad kind");
214+
215+
if (!Value)
216+
return constructError("bad path");
217+
212218
auto *KindNode = dyn_cast<llvm::yaml::ScalarNode>(Key);
213219
if (!KindNode)
214220
return constructError("kind not a ScalarNode");

test/Driver/malformed-ofm.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Ensure that an incomplete output-file-map path does not crash the driver,
2+
// but instead outputs a nice diagnostic.
3+
//
4+
// RUN: %empty-directory(%t)
5+
// RUN: split-file %s %t
6+
// RUN: not %swiftc_driver -c %S/../Inputs/empty.swift -output-file-map %t/malformed-output-file-map.json 2>&1 | %FileCheck %s
7+
//
8+
// CHECK: error: Expected quote at end of scalar
9+
// CHECK-NOT: Assertion failed
10+
11+
//--- malformed-output-file-map.json
12+
{
13+
"/path/to/some/file.swift": {
14+
"dependencies": "

0 commit comments

Comments
 (0)