@@ -332,6 +332,19 @@ static void discoverCrosssImportOverlayDependencies(
332
332
allModules.end (), action);
333
333
}
334
334
335
+ namespace {
336
+ std::string quote (StringRef unquoted) {
337
+ llvm::SmallString<128 > buffer;
338
+ llvm::raw_svector_ostream os (buffer);
339
+ for (const auto ch : unquoted) {
340
+ if (ch == ' \\ ' )
341
+ os << ' \\ ' ;
342
+ os << ch;
343
+ }
344
+ return buffer.str ().str ();
345
+ }
346
+ }
347
+
335
348
// / Write a single JSON field.
336
349
template <typename T>
337
350
void writeJSONSingleField (llvm::raw_ostream &out, StringRef fieldName,
@@ -342,14 +355,14 @@ void writeJSONSingleField(llvm::raw_ostream &out, StringRef fieldName,
342
355
void writeJSONValue (llvm::raw_ostream &out, StringRef value,
343
356
unsigned indentLevel) {
344
357
out << " \" " ;
345
- out << value;
358
+ out << quote ( value) ;
346
359
out << " \" " ;
347
360
}
348
361
349
362
void writeJSONValue (llvm::raw_ostream &out, swiftscan_string_ref_t value,
350
363
unsigned indentLevel) {
351
364
out << " \" " ;
352
- out << get_C_string (value);
365
+ out << quote ( get_C_string (value) );
353
366
out << " \" " ;
354
367
}
355
368
@@ -615,7 +628,7 @@ static void writeJSON(llvm::raw_ostream &out,
615
628
const auto &arg =
616
629
get_C_string (swiftTextualDeps->command_line ->strings [i]);
617
630
out.indent (6 * 2 );
618
- out << " \" " << arg << " \" " ;
631
+ out << " \" " << quote ( arg) << " \" " ;
619
632
if (i != count - 1 )
620
633
out << " ," ;
621
634
out << " \n " ;
@@ -630,7 +643,7 @@ static void writeJSON(llvm::raw_ostream &out,
630
643
const auto &candidate = get_C_string (
631
644
swiftTextualDeps->compiled_module_candidates ->strings [i]);
632
645
out.indent (6 * 2 );
633
- out << " \" " << candidate << " \" " ;
646
+ out << " \" " << quote ( candidate) << " \" " ;
634
647
if (i != count - 1 )
635
648
out << " ," ;
636
649
out << " \n " ;
@@ -654,7 +667,7 @@ static void writeJSON(llvm::raw_ostream &out,
654
667
const auto &arg =
655
668
get_C_string (swiftTextualDeps->extra_pcm_args ->strings [i]);
656
669
out.indent (6 * 2 );
657
- out << " \" " << arg << " \" " ;
670
+ out << " \" " << quote ( arg) << " \" " ;
658
671
if (i != count - 1 )
659
672
out << " ," ;
660
673
out << " \n " ;
0 commit comments