Skip to content

Commit 79928ad

Browse files
authored
Make sure we handle a supplementary output list with no outputs in it (swiftlang#18117)
1 parent 3ef0271 commit 79928ad

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

include/swift/Frontend/OutputFileMap.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ namespace swift {
3030

3131
using TypeToPathMap = llvm::DenseMap<file_types::ID, std::string>;
3232

33+
/// A two-tiered map used to specify paths for multiple output files associated
34+
/// with each input file in a compilation job.
35+
///
36+
/// The structure is a map from input paths to sub-maps, each of which maps
37+
/// file types to output paths.
3338
class OutputFileMap {
3439
private:
3540
llvm::StringMap<TypeToPathMap> InputToOutputsMap;
@@ -73,7 +78,10 @@ class OutputFileMap {
7378
/// Dump the OutputFileMap to the given \p os.
7479
void dump(llvm::raw_ostream &os, bool Sort = false) const;
7580

76-
/// Write the OutputFilemap for the \p inputs so it can be parsed.
81+
/// Write the OutputFileMap for the \p inputs so it can be parsed.
82+
///
83+
/// It is not an error if the map does not contain an entry for a particular
84+
/// input. Instead, an empty sub-map will be written into the output.
7785
void write(llvm::raw_ostream &os, ArrayRef<StringRef> inputs) const;
7886

7987
private:

lib/Frontend/OutputFileMap.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,19 @@ static void writeQuotedEscaped(llvm::raw_ostream &os,
110110
void OutputFileMap::write(llvm::raw_ostream &os,
111111
ArrayRef<StringRef> inputs) const {
112112
for (const auto input : inputs) {
113+
writeQuotedEscaped(os, input);
114+
os << ":";
115+
113116
const TypeToPathMap *outputMap = getOutputMapForInput(input);
114-
if (!outputMap)
117+
if (!outputMap) {
118+
// The map doesn't have an entry for this input. (Perhaps there were no
119+
// outputs and thus the entry was never created.) Put an empty sub-map
120+
// into the output and move on.
121+
os << " {}\n";
115122
continue;
116-
writeQuotedEscaped(os, input);
117-
os << ":\n";
123+
}
124+
125+
os << "\n";
118126
for (auto &typeAndOutputPath : *outputMap) {
119127
file_types::ID type = typeAndOutputPath.getFirst();
120128
StringRef output = typeAndOutputPath.getSecond();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Check that we can handle /no/ supplementary outputs.
2+
// RUN: %target-build-swift -typecheck -driver-filelist-threshold=0 %s

0 commit comments

Comments
 (0)