Skip to content

Commit 39d2b6a

Browse files
author
git apple-llvm automerger
committed
Merge commit 'b49bdc1ce02c' from apple/main into swift/next
2 parents fe1987b + b49bdc1 commit 39d2b6a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

clang/lib/Basic/SourceManager.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
111111
if (!ContentsEntry)
112112
return None;
113113

114+
// Start with the assumption that the buffer is invalid to simplify early
115+
// return paths.
116+
IsBufferInvalid = true;
117+
114118
// Check that the file's size fits in an 'unsigned' (with room for a
115119
// past-the-end value). This is deeply regrettable, but various parts of
116120
// Clang (including elsewhere in this file!) use 'unsigned' to represent file
@@ -125,7 +129,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
125129
Diag.Report(Loc, diag::err_file_too_large)
126130
<< ContentsEntry->getName();
127131

128-
IsBufferInvalid = true;
129132
return None;
130133
}
131134

@@ -145,7 +148,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
145148
Diag.Report(Loc, diag::err_cannot_open_file)
146149
<< ContentsEntry->getName() << BufferOrError.getError().message();
147150

148-
IsBufferInvalid = true;
149151
return None;
150152
}
151153

@@ -161,7 +163,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
161163
Diag.Report(Loc, diag::err_file_modified)
162164
<< ContentsEntry->getName();
163165

164-
IsBufferInvalid = true;
165166
return None;
166167
}
167168

@@ -174,10 +175,11 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
174175
if (InvalidBOM) {
175176
Diag.Report(Loc, diag::err_unsupported_bom)
176177
<< InvalidBOM << ContentsEntry->getName();
177-
IsBufferInvalid = true;
178178
return None;
179179
}
180180

181+
// Buffer has been validated.
182+
IsBufferInvalid = false;
181183
return Buffer->getMemBufferRef();
182184
}
183185

0 commit comments

Comments
 (0)