@@ -111,6 +111,10 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
111
111
if (!ContentsEntry)
112
112
return None;
113
113
114
+ // Start with the assumption that the buffer is invalid to simplify early
115
+ // return paths.
116
+ IsBufferInvalid = true ;
117
+
114
118
// Check that the file's size fits in an 'unsigned' (with room for a
115
119
// past-the-end value). This is deeply regrettable, but various parts of
116
120
// Clang (including elsewhere in this file!) use 'unsigned' to represent file
@@ -125,7 +129,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
125
129
Diag.Report (Loc, diag::err_file_too_large)
126
130
<< ContentsEntry->getName ();
127
131
128
- IsBufferInvalid = true ;
129
132
return None;
130
133
}
131
134
@@ -145,7 +148,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
145
148
Diag.Report (Loc, diag::err_cannot_open_file)
146
149
<< ContentsEntry->getName () << BufferOrError.getError ().message ();
147
150
148
- IsBufferInvalid = true ;
149
151
return None;
150
152
}
151
153
@@ -161,7 +163,6 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
161
163
Diag.Report (Loc, diag::err_file_modified)
162
164
<< ContentsEntry->getName ();
163
165
164
- IsBufferInvalid = true ;
165
166
return None;
166
167
}
167
168
@@ -174,10 +175,11 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
174
175
if (InvalidBOM) {
175
176
Diag.Report (Loc, diag::err_unsupported_bom)
176
177
<< InvalidBOM << ContentsEntry->getName ();
177
- IsBufferInvalid = true ;
178
178
return None;
179
179
}
180
180
181
+ // Buffer has been validated.
182
+ IsBufferInvalid = false ;
181
183
return Buffer->getMemBufferRef ();
182
184
}
183
185
0 commit comments